OK, so I'm showing a big grid that's bound to a data set and then I'm attaching a new column for a checkbox for item selection - pretty common scenario I'd think. However I want the checkboxes to default to unchecked and for the life of me I can't get it to work. they show up as checked but "gray" and evaluate to null. You can check and uncheck them at which point they look "normal" and evaluate to true/false as you'd expect.
So is there a trick to the .DefaultCellValue = xxx that I'm missing here?
thanks
Hi,
DefaultCellValue only affects rows added by the user. If you have data in your grid and you are using an unbound column to show checkboxes, the DefaultCell Value won't help you there.
My guess is that you are adding an unbound column to the grid and setting the Style on the column to CheckBox, but you are not setting the DataType. If you don't set the DataType, it defaults to string, so this will end up displaying as the indeteminate state in every cell.
What you should do is set the DataType on the column to bool. This will default the value of the cell to false and you don't need to set the Style on the column, since a bool column defaults to checkbox style
Oh... and if you ever do need to initialze the value of an unbound column, the place to do it is in the InitializeRow. You would check to make sure e.ReInitialize is false, so you only set the value the first time.
yeah - that was it - works fine now.
-J
I have an issue , mine is a bound column and the DataType is set to string but I want to change the DefaultCellValue to null but it cant let me for this particular grid . I see it possible with other grids. Please help
I do not understand your question. There's no way to unbind a bound column. If you want the cell to default to null, why do you need to do anything? Doesn't your data source automatically default the value to null? If not, what does it default to? What kind of DataSource are you using for the grid?
It defaults it to N and the DataSource is a table
What exactly is a "table"? There is no such data type that I am aware of. Do you mean a DataTable?
In any case, why can't you set the DefaultCellValue to DBNull.Value? What's the problem?Are you getting an error?
Perhaps what you should do is handle the BeforeRowInsert event and set the value on the cell to DBNull.Value instead of using DefaultCellValue.
Thank you the InitializeTemplateAddRow worked just fine. I appreciate the help
Thanks
Hi Alex,
Why does the field default to N? That must be coming from the DataTable, the grid cannot be doing that. So you might try changing the default value on the DataTable column instead of in the grid.
Setting DefaultCellValue should work. What exactly do you mean when you say "it just won't let me?" How is it stopping you?
shyakaster said: protected void BeforeRowInsert(Infragistics.Win.UltraWinGrid.BeforeRowInsertEventArgs e) { //This does not help grdApprovalRoles.InitializeTemplateAddRow = DBNull.Value; }
protected void BeforeRowInsert(Infragistics.Win.UltraWinGrid.BeforeRowInsertEventArgs e)
{
//This does not help
grdApprovalRoles.InitializeTemplateAddRow = DBNull.Value;
}
The code you have here does not make sense and cannot possibly compile. InitializeTemplateAddRow is an event, you can't set an event to DBNull. If you want to use BeforeRowInsert, then you need to set the Value of the cell in the TemplateAddRow.
But you would be better off using the InitializeTemplateAddRow event and setting the Value of the appropriate cell inside that event.
When I click on a row in a grid another row is created below that and is populated with a DefaultCellValue of N which I have failed to change from the UltraGridDesigner so Ihave decided to change that from a BeforeRowInsert event below
How would I code this to make sure the row created below when I click on a row is null(not populated with any values). Please help am a novice.
Alex
Sorry I meant datatable and the DBNull angle is not working as well.It just wont let me