Hi,
I have a column with ColumnStyle.CheckBox, it is a unbound column. The column shows null value after I execute SetDataBinding. I wanna shows checked or unchecked state , I think there is a default value for me, How I do?
Thanks!
Hi Jason,
You can set the DefaultCellValue property on the column.
But it seems not work well. I set the defaultcellvalue in InitializeLayout ,and when a button click for call SetDataBinding. when DefaultCellValue = False ,it works well ,but when DefaultCellValue = True , it is not ok, it always show the False state. it is my test code. by the way , when I set the column datatype as string , it is not work well yet.
Private Sub UltraGrid1_InitializeLayout(ByVal sender As Object, ByVal e As Infragistics.Win.UltraWinGrid.InitializeLayoutEventArgs) Handles UltraGrid1.InitializeLayout UltraGrid1.DisplayLayout.AddNewBox.Hidden = False
With e.Layout.Bands(0) If Not .Columns.Exists("COL1") Then .Columns.Add("COL1") .Columns("COL1").DataType = GetType(Boolean) .Columns("COL1").DefaultCellValue = True End If If Not .Columns.Exists("COL2") Then .Columns.Add("COL2") .Columns("COL2").DataType = GetType(String) End If End With End Sub
Private Sub UltraButton1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles UltraButton1.Click UltraGrid1.SuspendLayout()
Dim dt As New DataTable Dim dr As DataRow dt.Columns.Add("COL2", GetType(String)) For i As Integer = 0 To 9 dr = dt.NewRow dr.Item("COL2") = CStr(i + 4) dt.Rows.Add(dr) Next dt.AcceptChanges() UltraGrid1.SetDataBinding(dt, Nothing, True)
End Sub
Sorry, it looks like DefaultCellValue only works for new rows. Try this:
Private Sub UltraGrid1_InitializeRow(sender As System.Object, e As Infragistics.Win.UltraWinGrid.InitializeRowEventArgs) Handles UltraGrid1.InitializeRow If Not e.ReInitialize AndAlso e.Row.Cells.Exists("COL1") Then e.Row.Cells("Col1").Value = True End If End Sub
Hi, Mike
Really Great! I'm just a little concerned about performance cos the initialrow event is looped each row in my code.
Jason
I wouldn't worry too much about performance unless you have a really huge number of rows. Anyway, there isn't any other way to do this - other than adding the column to your data source and giving the DataColumn a default value.
Hi,Mike
Yes, modify datasource column will definitely affect my business layer, I used your code, it runs perfect! I have tested performance(not very huge data) ,it's ok. Thanks very much Mike!