Hello,
I'm using a WinGrid with unbound columns that may be added at runtime. These column data values are not IConvertible to strings. I use the InitializeRow event to populate the unbound column. Also, I'm using LoadOnDemand so not all rows are initialized.
I am getting an exception based on the order of events:
1) Add / Insert column - seems it has to be a new column with default DataType Text.
2) This immediately triggers the Initialize Row event which tries to populate the cell.Value and throws an exception based on Value type is not IConvertible.
3) Then run the configure code that sets the column dataType and other parameters (I'm actually using a DropDown with a ValueList to show icons reflecting object types).
Is there any way to configure a column and then add it to the WinGrid? Or is there any way to defer the InitializeRow event til after the column has been configured (SuspendRowSynchronization doesn't seem to delay these events)? Or is there a way to trigger the InitializeRowEvent again after configuration but only for the rows already initialized?
Thanks for any suggestions.
Wendy
Hi,
You can generally suspend events using the EventManager eg.
YourGrid.EventManager.IsEnabled(GridEventIds.InitializeRow, false);
You can also trigger InitilizeRow by calling:
YourGrid.Rows.Refresh(RefreshRow.FireInitializeRow, true);
Ryan
Sorry that should read - YourGrid.EventManager.SetEnabled.(GridEventIds.InitializeRow, false)
You're suggestion for EventManager.SetEnabled is working for turning on/off the InitializeRow events.
I use the InitializeRow event to set the value on several unbound columns. Grid.Refresh(FireInitializeRow, true) triggers initializing all grid rows. For large datasets, this becomes inefficient as all rows then need to be kept updated.
A workaround to obtain only the initialized rows is
for (int idx = 0; idx < myGrid.Rows.Count; idx++)
{ ugRow = picMBGrid1.Grid.Rows.GetRowWithListIndex(idx, false);
if (ugRow == null)
continue;
yield return ugRow; }
This will loop through all rows but does not Initialize all rows.
With the two fixes, I can add columns, then initialize the rows without creating more rows.