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??
So check e.Row.Cells.Exists("column name") inside InitializeRow before you try to set the value on the cell.
Hi,
I have two related questions on the same topic. How can I set the values to unbound columns without firing initilizerow event. or How can I force a row to get into initializerow event.
My problem is that I have a grid with 20 unbound columns and I have a time intensive functions which compute values for these columns. initializeRow event is fired for the first time the rows are displayed. so far so good. But, after the grid is displayed then also I have to compute values for these columns depending on my business class events. But, then when I set a value to these unbound columns, Initilizerow event is fired again resulting in unnecessary computation. I want to compute values only once. Therefore, I am looking for a possiblity to set the values for unbound columns by suppressing the INITIALIZEROW event or It is also fine, if I can select certain rows and mark them for intializerow event when I show the grid next time.
Thanks,
reddy.
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.
that got me thinking and it helped, thanks
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.
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?