ThreeState check box

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Infog
    New Member
    • Dec 2008
    • 36

    ThreeState check box

    I have a DataGridView that has columns with a value type of boolean.

    To load the DataGridView, I load values into a DataTable then set
    Code:
    theDataGridView.DataSource = theTable
    What value can I use in the table to load an intermediate check state?
    Would it be better to use a check box control with a value than to use a column set to the boolean data type?

    The check box is for display only, and will not need to be changed.
  • Plater
    Recognized Expert Expert
    • Apr 2007
    • 7872

    #2
    If it doesn't need to be changed, and the column is boolean, shouldn't you only need true/false ?

    Comment

    • Infog
      New Member
      • Dec 2008
      • 36

      #3
      There are three states that I would like to show - The employee doesn't have a certain certification (False), the employee does have a certain certification (True), or the employee has a certification that has been flagged for review (Intermediate).

      I was hoping that a data table could be used to store the value of an intermediate check state. That would allow me to not manually add each check box column in the DataGridView. If the boolean column in the data table is not recognized as needing three-state check boxes, I may skip using the table and add every column/row directly to the DataGridView.

      Comment

      • Plater
        Recognized Expert Expert
        • Apr 2007
        • 7872

        #4
        Why not use an integer column? 0,1,-1?
        Or even a simple text "CERT" "FLAG" "NOCERT"

        Comment

        • Infog
          New Member
          • Dec 2008
          • 36

          #5
          I hadn't really thought about using text... it would look nicer if it were check boxes though.

          I've been learning a lot of useful things about DataGridViews along the way, so I think I'll keep working towards my goal of using a three-state check box to show the summary of my data.

          At least now I know one method that will NOT work. :)

          Comment

          • Plater
            Recognized Expert Expert
            • Apr 2007
            • 7872

            #6
            Hmm, if you have a checkbox column, somewhere in there is like the underlying datatype (a checkbox)
            if you can get to that object, you can set it to be a tri-state checkbox maybe?

            Comment

            • cloud255
              Recognized Expert Contributor
              • Jun 2008
              • 427

              #7
              Well you could always create a custom control that has three states.

              You can then use a nullable Boolean value to represent the states. This will also allow you to map directly to a Boolean field in your database (Many databases consider a boolean to have 3 states: true, false and null).

              You declare a nullable Boolean like this:

              Code:
              Nullable<bool> MyThreeStateBool;
              But I agree with Plater that a bool is probably not the best data type to use, a combo box would be far less of a hassle to implement.

              Comment

              Working...