Hi
I using UltraWinGrid in my VB.NET windows application. I have two unbound columns in my Grid.
I have written code in Grid_InitializeLayout event to add unbound columns.
I want to set values in the unbound columns based on the values in the others cells of every row.
I have used Grid_Initializerow event to do this. This event is fired when i set the Datasource to the grid and the values are set in the unbound cells as per the condition given.
But this event is fired again when i change the values in the unbound columns and the values are set again.
Can i prevent the Initializerow event from firing when user edits the unbound columns?
What is the best way to bind values to unbound columns based on the values in the other cells?
Ashok
Hi Ashok,
You should check the e.ReInitialize property inside InitializeRow to see if the row is being initialized for the first time or not. So only set the unbound cell value when e.ReInitialize is false.
Hi Mike
I am adding unbound columns in Grid_InitializeLayout event. When i assign the datasource to the Ultragrid, Grid_InitializeRow event is fired first and then it goes to Grid_InitializeLayout.
So in Grid_InitializeRow event When i access the unbound cell using column key it gives an error "Key not found"
Grid_InitializeRow is also fired when i change the values in the cell and causing problems.
Is there any other work around to bind values to Unbound columns(only when datasource is assigned to Grid) based on the values in other cells of the row??
Hi Reddy,
It sounds like you should be checking inside the InitializeRow event for e.ReInitialize and only do your computations when it's false. That way it will only happen the first time the event fires on each row.
If you need to update the data later and want to do it all at once, then you can call BeginUpdate on the grid, change all the values you want, then call EndUpdate. I think InitializeRow will fire for all the rows that needed it at that point. But I may be wrong about that. If I am, then you can call grid.Rows.Refresh(FireInitializeRow) to force it to fire.
Hi Mike,
Is the only way to update cell values on an unbound column throught the InitializeRow event?
No, that's not the only way, but it's usually the best way. You can also loop through the rows or get a reference to a row in any number of other ways and update the value directly.
Unfortunatly, the functionality im trying to create cannot be accomplished in the initializerow event.
I have tried updating the value of the unbound column in a foreach loop going through the grid, and while debugging the value gets stored in the column's value property. But when viewing the grid the value is not displayed. I have guaranteed that the columns allow update property is true, and i set it in the initializerow event as well as the initializelayout event.
Any ideas what could be causing this behavior?
Hi Chris,
The grid cell will display whatever it's current value is. If the value you are setting is not showing up, then either you are not setting it correctly, or something else is setting it to the value that is being displayed after you set it.
that got me thinking and it helped, thanks