Hi.
My question is - when I data bind grid to data source, boolean data will be interpreted as checkbox, i.e. true will cause the checkbox to be checked , and false will cause the checkbox to be unchecked. The question is - is there a data type which corresponds tri-state check box (i.e. checked, unchecked, disabled) and can control all of its states, or do I need to use boolean field and control disabled state via some other variable and AllowEdit property?
I think that a nullable boolean should work for this ("bool?" or Nullable<bool>). In some cases, the data source will allow DBNull.Value as well, in which case you could use a TriStateCheckBox as the column's Style.
-Matt
Actually, it's even worse. I haven't tried using nullable bool with any value other than null before.
Now i did, and when using nullable bool it displays "False" and "True" as strings, not as checkbox.
I'm not really sure that I understand the question, what state are you referring to? Are you trying to update the status of the row based on this checkbox?
No.
I mean that when you databind the grid, each possible value of the data field has it's representation in the cell, i.e. false will result in unchecked checkbox, true will result in checked checkbox. Null results in grayed checked checkbox, while i need it to result in grayed unchecked checkbox. Is there a way to define style behaviour?
I don't think that the checkbox should be appearing as disabled, unless your particular style of checkbox happens to look that way for an indeterminate state; it sounds like the UseOsThemes property of your grid is set to false, so this is how an indeterminate checkbox will appear. There are two different ways that you can control checkbox behavior in general:
1) Use a DataFilter to determine what should be considered True, False, or Indeterminate/Null. There is a KB article on using a DataFilter with checkboxes.
2) Use the GlyphInfo property of an UltraCheckEditor to control what the checked, unchecked, and indeterminiate styles are for the various states of a checkbox, then assign this UltraCheckEditor as the EditorControl of the column. I believe that the glyph functionality was introduced with the 8.2 release of NetAdvantage.
In your case, it sounds like you're interested in changing the appearance, and not what is considered checked/unchecked, so the second option is your best bet if you can't set UseOsThemes to True.
Hi,Matt.
Ok, I might be getting the idea.
Anyway, this is all becomes more complicated since I need the checkbox to become disabled and uneditable (and not only visually grayed out). Since we're using multi-band grid, i see no other option but access each cell independently while changing its editable state.
You only need to set some of these more general properties on the column level, but it's true that if you want to disable cells/rows in certain states, you need to be a little more granular. This is a lot easier if you handle the InitializeRow event, since this will fire again when the value of any cells in the row changes, so you could simply check the value of the cell (via row.GetCellValue or just row.Cells[key].Value). At least in this way you can form a structure based on the different bands in your grid, or if the key of the column is the same in all bands you simply can do this in InitializeRow regardless of band.