I'm displaying a summary grid for an installer. I need to alter the groupby col image dynamically. I've messed with this quite a bit but I can't seem to make a dent.
The attached pic shows what I'm getting now, but I need the groupby header to show a check if they all pass, and an X if even one of them fails.
Hello,
Thank you for the provided image.
What I can suggest for achieving your requirement is using the InitializeGroupByRow event, which is fired for each group by row after the grid is initialized.
All rows in a particular group can be retrieved in the event. A local Boolean variable, initially set to true, can be declared. Afterward, by looping through all rows for a particular group we can set the variable`s value based on whether there is a negative value in the record. If there is a false value we break the loop since the condition is to render the negative icon if at least one value is false. In case that all values are positive the variable`s value is set to true. As next step, the icon for this group by row is set based on the flag.
I have created a small sample illustrating my suggestion. The Status column is boolean, however, the logic would be the same for values OK/Failed.
private void ultraGrid1_InitializeGroupByRow(object sender, InitializeGroupByRowEventArgs e) { var grouped_rows = e.Row.Rows; bool flag = true; string parent = Directory.GetParent(Directory.GetCurrentDirectory()).Parent.FullName; foreach (var _row in grouped_rows) { string value = _row.Cells[5].Value.ToString(); if (value == "False") { flag = false; break; } } if (flag) { e.Row.Appearance.Image = new Bitmap(parent + "\\tick.webp"); } else { e.Row.Appearance.Image = new Bitmap(parent + "\\Warning.svg.png"); } }
Attached you will find my sample for your reference. Please test it on your side and let me know how it behaves. If this is not an accurate demonstration of what you are trying to achieve please feel free to modify it and send it back to me along with steps to reproduce. Alternatively, if the behavior cannot be replicated please feel free to provide your own sample. Remove any external dependencies and code that is not directly related to the issue, zip your application and attach it in this case.
Having a working sample on my side, which I can debug, is going to be very helpful in finding the root cause of this behavior.
Thank you for your cooperation.
Looking forward to hearing from you.
Sincerely,
Teodosia Hristodorova
Associate Software Developer
0474.UltraGridGroupByRowImages.zip
Thanks for that. It looks like it should work just fine, but for some reason it didn't exactly what it looks like it should. It did however show me what I was doing wrong and I got it worked out. Here's the version I got working.
var grouped_rows = e.Row.Rows; bool flag = true; //string parent = Directory.GetParent(Directory.GetCurrentDirectory()).Parent.FullName; foreach (var _row in grouped_rows) { e.Row.Appearance.Image = Image.FromFile(@".\Images\Check.jpg"); string value = _row.Cells["Status"].Value.ToString(); if (value == "Failed") { e.Row.Appearance.Image = Image.FromFile(@".\Images\X.jpg"); break; } }