Connecting Tech Pros Worldwide Forums | Help | Site Map

ThreeState check box

Member
 
Join Date: Dec 2008
Location: Riverside, CA
Posts: 32
#1: Jul 31 '09
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
Expand|Select|Wrap|Line Numbers
  1. 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's Avatar
Moderator
 
Join Date: Apr 2007
Location: New England
Posts: 7,161
#2: Jul 31 '09

re: ThreeState check box


If it doesn't need to be changed, and the column is boolean, shouldn't you only need true/false ?
Member
 
Join Date: Dec 2008
Location: Riverside, CA
Posts: 32
#3: Jul 31 '09

re: ThreeState check box


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.
Plater's Avatar
Moderator
 
Join Date: Apr 2007
Location: New England
Posts: 7,161
#4: Jul 31 '09

re: ThreeState check box


Why not use an integer column? 0,1,-1?
Or even a simple text "CERT" "FLAG" "NOCERT"
Member
 
Join Date: Dec 2008
Location: Riverside, CA
Posts: 32
#5: Jul 31 '09

re: ThreeState check box


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. :)
Plater's Avatar
Moderator
 
Join Date: Apr 2007
Location: New England
Posts: 7,161
#6: Jul 31 '09

re: ThreeState check box


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?
Expert
 
Join Date: Jun 2008
Location: Pretoria, South Africa
Posts: 410
#7: Aug 1 '09

re: ThreeState check box


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:

Expand|Select|Wrap|Line Numbers
  1. 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.
Reply

Tags
checkbox, datagridview, datatable, threestate


Similar Visual Basic .NET bytes