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 believe that you need to explicitly set the Style property of the column when using this type, i.e.
private void ultraGrid1_InitializeLayout(object sender, Infragistics.Win.UltraWinGrid.InitializeLayoutEventArgs e){ e.Layout.Bands[0].Columns[0].Style = Infragistics.Win.UltraWinGrid.ColumnStyle.TriStateCheckBox;}
Actually, that's what I was trying to avoid (using multi-band grid).
Anyway, another question - the state for "null" value is "selected-disabled".
Is it possible for it to be "not selected-disabled"?
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.
Ok. Let me try to explain from the beginning.
I'm trying to display a multi-band databound grid.
One column (which appears in each row of the grid) should display a checkbox.
This checkbox represents a boolean field of the data source (datasource is an List <>, not a direct recordset from database).
I need this checkbox to be checked when the field contains "true" and unchecked when it contains "false", which is exactly what happens when the field is boolean, so far, so good.
Now I need this checkbox to become grayed (disabled) and blocked for editing, based either on the additional value of the datasource field (i.e. null for nullable boolean) or any other criteria (value of additional hidden cell in the same row, etc).
How do I achieve that most efficiently (i.e. without traversing each row in the grid)?
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.
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.
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?