We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date
close icon

CheckBox Column Tristate Indeterminate Value

The CheckboxOptions of the GridStyleInfo object has a string datatype for the IndetermValue property. The problem is my bound column (Db Constraint) accepts "Y", "N" and null as valid values. How do I get the grid to push DbNull.Value when the user clicks to the third Indeterminate option? When I use DbNull.Value.ToString() it''s just an empty string (""), so thats what the bound column gets, instead of the desired value of DbNull.

3 Replies

AD Administrator Syncfusion Team July 25, 2005 08:36 AM UTC

You can try handling the grid.Model.SaveCellInfo event, and swap out the value before it gets saved.
private void Model_SaveCellInfo(object sender, GridSaveCellInfoEventArgs e)
	if(e.Style.CellType == "CheckBox" 
		&& e.Style.CellValue != null 
		&& e.Style.Text.Length == 0)
		e.Style.CellValue = DBNull.Value;

AD Administrator Syncfusion Team July 26, 2005 02:45 AM UTC

Thank-you that works. Is there like an internal reason why the data types of the CheckBoxOptions have to be strings? Perhaps if they were instead of type object, than supplying DbNull.Value or anything else would be an option, instead of attaching to the prescribed event?

AD Administrator Syncfusion Team July 26, 2005 07:24 AM UTC

The checkbox options determined what is displayed in the cell. For example, if CellValueType is bool, then a bool value is stored in the cell, and you set the display values in the check box options to be "true", "false" and "" as that is what will be displayed as text in the cell. Here, a DBNull.Value is stored as the indeterminate value since when the grid converts a "" to a bool it comes up with DBNull. But in your case, you actually are storing strings ("Y", "N") as the cell values so this means the CellValueType must be string. When the grid then tries to convert the indeterminate value "" to string, well it already is a string, so the grid leaves it alone. The grid does not know you want it to change the empty string into a DBNull since the cellvaluetype is string and the empty string is a valid string. So, in your use case, swapping the empty string for DBNull takes the additional work of handling an event. If your cellvaluetype was bool, this would not be needed.

Live Chat Icon For mobile
Up arrow icon