Hi all,I am currently facing a strange problem with the WinGrid.It is a standard WinGrid, bound to an object datasource (List<item>).I added an UnboundColumn to display a "light" icon that indicates its status (red, green).On InitializeRow the calculation is done and a predefined (for reuse) Appearance is assigned to the cell (unbound column).Now imagine the following rows (Id, IndicatorImage):1 green2 green3 red4 red
now if I remove the data entry from the datasource that contains Id = 2 I assumed to have the following rows:1 green3 red4 red
Unfortunately I get this:1 green3 green4 red
It seems that the indicator image stays the same for the rows (the bottom one is removed though)
Any hint is kindly appreciated,best regardsAndy
Hi Andy,
Can you post your InitializeRow code so I can see what it's doing? It seems to me that, since the color on the existing row is changed, the InitializeRow must be firing for that row and the InitializeRow code must therefore be applying the wrong Appearance to the row.
Also, what version of the grid are you using? It's also possible that this is a bug in a very old version of the grid where it's re-using the UIElements incorrectly. But that bug was fixed many years ago.
Hi Mike,
good hearing from you, I hope you are doing fine.
Here is the InitializeRow code:
void grdBalance_InitializeRow(object sender, InitializeRowEventArgs e) { if (e.Row.GetType() == typeof(UltraGridRow)) { // checking flag-state ParsedBalanceStorageListEntry entry = e.Row.ListObject as ParsedBalanceStorageListEntry; int count = GetCountFromItem(entry); if (count == 0) { e.Row.Cells[TrafficLightColumnKey].Appearance = RedMarkerAppearance; return; } if (count == 1) { e.Row.Cells[TrafficLightColumnKey].Appearance = GreenMarkerAppearance; return; } e.Row.Cells[TrafficLightColumnKey].Appearance = YellowMarkerAppearance; return; } }
...and the stuff related to the appearances I use:
private Appearance _greenMarkerAppearance; private Appearance GreenMarkerAppearance { get { if (_greenMarkerAppearance == null) { _greenMarkerAppearance = GetDefaultTrafficLightAppearance("GreenMarkerAppearance"); _greenMarkerAppearance.Image = GlobalResources.Images.Misc.Flags.NonCountryFlags.NonCountryFlagsImageProvider.FlagGreen.ResizeTo(new Size(16, 16)); } return _greenMarkerAppearance; } } private Appearance _redMarkerAppearance; private Appearance RedMarkerAppearance { get { if (_redMarkerAppearance == null) { _redMarkerAppearance = GetDefaultTrafficLightAppearance("RedMarkerAppearance"); _redMarkerAppearance.Image = GlobalResources.Images.Misc.Flags.NonCountryFlags.NonCountryFlagsImageProvider.FlagRed.ResizeTo(new Size(16, 16)); } return _redMarkerAppearance; } } private static Appearance GetDefaultTrafficLightAppearance(string key) { Appearance appearance = new Appearance(key); appearance.ImageHAlign = HAlign.Center; appearance.ImageVAlign = VAlign.Top; return appearance; }
I use this to meet the guidelines I read about in your UltraGrid Tuning-Tips article for reusing appearances.
We are currently using version 11.2.20112.1010, so I assume that is already a version where the mentioned bug was fixed ;)
Let me know if you need any further information.
Best regards and have a great dayAndy