Have been up all night trying to figure this one out. I am using an Infragistics.Win.UltraWinGrid.UltraGrid. The DataSource for the grid is a BindingSource that uses a custom data structure. Binding and property updates are working fine. Grid is readonly.I want to change the color (toggle) of a row if the underlying value changes. Here is a very simplified snippet of my original code using the recommended InitializeRow event (note, for simplification I am just coloring the whole row for the example, whereas actually I am coloring a cell in my application):private void ugWatchlist_InitializeRow(object sender, Infragistics.Win.UltraWinGrid.InitializeRowEventArgs e){ if (!e.ReInitialize) return; Infragistics.Win.Appearance app1 = new Infragistics.Win.Appearance(); app1.BackColor = Color.Green; Infragistics.Win.Appearance app2 = new Infragistics.Win.Appearance(); app2.BackColor = Color.Red; if (e.Row.Appearance.BackColor.Name != Color.Green.Name) e.Row.Appearance = app1; else e.Row.Appearance = app2;}However, the color change works only once (and rows turn red on the firs t update and stay that way). According to the code, the color should toggle on each update. I can confirm in the debugger that the BackColor property is indeed changed but not reflected by the UltraGrid.Am I missing something here? I have gone through all the samples and examples and couldn't find a solution to this problem. Please help.
Hi,
I'm not sure why the color is only changing once, but the code you have here is not going to work in any case.
You are making the assumption that the only time the InitializeRow event will fire is when something in the row has changed. That might be the case, but it's not really a good assumption to make. The event might fire for some other reason. For example, you could call grid.Rows.Refresh and force it to fire again for all rows.
So your code here is essentially going to toggle the BackColor of the row at random.
If you want to track rows that have changes in them, you need to come up with a better way of determining when a change occurs and what exactly you mean by this.
What does it mean for a cell value to change? Change from what? When does it become "not changed" again? Does a change mean that the row has changes that have not yet been committed to the data source? Or does it mean that the DataSource has changes that have not been committed back to the database?
Also... declaring new Appearance objects inside the InitializeRow event is incredibly wasteful and inefficient. You will be creating a huge number of identical objects and wasting massive amounts of memory. It would be better to create these two appearances inside the grid's InitializeLayout event and add them into the grid.DisplayLayout.Appearance collection and then just re-use the same two objects for as many rows (or cells) as you need.
Hi Mike,
Thanks for the reply.
1. The suggestions you made regarding code efficiency are correct. Note that the sample code I put here is a simplification, so that we can have it all in one place. In the real code I am not instantiating objects in the event handler.... so rest assured :) This has no direct logical implication though.
2. Yes, the color will be toggled at random. Again, this is sample code anyway. In the real code I am also tracking updates in my data structure using a boolean flag when the underlying property changes. So I have already covered that area.
3. Now, the pending issue is that the color is not changing. Even if its random it SHOULD toggle randomly. Right now it just stays red. I need to resolve this urgently. Any ideas? I have the latest Infragistics control that I download and installed yesterday.
Well, I'm not sure why it's not working, then. Have you tried putting a breakpoint in the InitializeRow to see if the code is actually firing and changing the Appearance on the row. Maybe the code is not setting the Appearance to the correct one? Maybe there a typo in the code and you are examining the wrong condition.