Hello,
This is in connection with my earlier post on Adding a New Unbound Row to WinGrid. Please refer to my Post as well as reply for the background scenario.
Now, based on the description, the new order in my ultragrid is actually in 2 states.
1. Pending: Order placed, waiting for admin approval
2. Approved: Order approved.
Now, I need to color the orders pending approvals. Once the orders are approved, the row color is reset to the default ones. Currently I have reset the color of the rows as WHITE background with BLACK as text color. I can color the rows at perticular index in the grid. But when the grid is sorted or grouped, the color is not(as it is colored based on indexes).
Can anyone suggest how should it be done?
Thanks a lot!
It's not a good idea to rely on the Index of a row, since the index can change. You should probably base the appearance of the row on a value of a cell within that row. You might also want to use the ListObject or ListIndex property of the row which return the underlying data object that the row is bound to or the index of that object in it's collection, respectively.
I could format the row with the PENDING status. I used the initialize row event of the datagrid which gave me the newly added row and I could format it accordingly.
Now, there is another problem. I need to reset the formatting of the row to the default one when I get the confirmation about the added order. Is there any way I can do that? Moreover, I happened to read about Conditional Formatting. Is there any way we can implement at run time as my datasource is populated and bound at run time.
Many Thanks!
Hi,
sagarbora said:Now, there is another problem. I need to reset the formatting of the row to the default one when I get the confirmation about the added order. Is there any way I can do that?
InitializeRow should fire for the row again when you change the value of any cell. So you just need to use an 'if' statement or a 'switch' inside InitializeRow to apply an appearance to the row or the cell based on the cell's current Value.
To revert the row back to the default appearance, you just reset the appearance you applied. So if you did something to the row.Appearance, you would call row.ResetAppearance. If it was a cell, you would do cell. ResetAppearance.
sagarbora said:Moreover, I happened to read about Conditional Formatting. Is there any way we can implement at run time as my datasource is populated and bound at run time.
Conditional Formatting is mainly for design-time. It's actually more difficult and needs more code to set this up at run-time, than it does to use the InitializeRow event.
Sounds good! Yes, I am checking whether the row is initialized for the first time or reinitialized. InitializeRow gets fired everytime I select any row. I am not allowing to update the row though.
Can you please advice in which event I can reset the appearance of the perticular row? Is it InitializeRow again or some different one. As I am modifying the underlying datasource, Before/AfterRowUpdate do not get fired. Currently I am restoring the appearance of the perticular row by looping through the rows of the grid. But looping through all rows is not quite efficient solution I guess. I believe there should be a way to do this more efficiently.
sagarbora said:Yes, I am checking whether the row is initialized for the first time or reinitialized.
Why? You really shouldn't care whether it's the first time or not. What you want to do is handle the event and examine the value in the cell or cells of the row and then either apply or reset the formatting accordingly. It does not matter if the row is being initialized the first time or the hundredth time.
sagarbora said:Can you please advice in which event I can reset the appearance of the perticular row? Is it InitializeRow again or some different one.
You only need InitializeRow and no other event.
Mike Saltzman"] Why? You really shouldn't care whether it's the first time or not. What you want to do is handle the event and examine the value in the cell or cells of the row and then either apply or reset the formatting accordingly. It does not matter if the row is being initialized the first time or the hundredth time.
Oh correct! I've tried this and it's working
But to reset the formatting. It's not firing the InitializeRow event once I update the datasource. I am not adding the new record to the datasource. I just update the datasource with the OrderID which I received in Order Confirmation message from the server. Before order is confirmed, this OrderID is 0
If changing a value in the data source is not firing the InitializeRow event of the grid, then your data source is not firing notifications when values change. This could be a bug in the data source or it could just be that you are using an IList data source. If that's the case, you can just call grid.Rows.Refresh(FireInitializeRow) when the value changes and this will force the grid to fire the event.
You might want to consider using a more robust data source that implements IBindingList, though.