Hi,
I have certain columns in my grid where I customize the GroupByRow description property in the OnIntializeGroupByRow handler. Lets say the default format of that description is "ColumnName : ColumnValue (# items)". I am customizing the ColumnValue part of the description string and leaving the rest alone as it is.
When I am grouped by this column and I delete rows from this group, the # items count does not update in real time. When I group by other columns where I am not customizing the GroupByRow description, the # items count will update right away. I see that OnInitializeGroupByRow does not fire when rows are deleted. How can I refresh my custom GroupByRow descriptions when data changes in the grid?
Thanks,
~Corey
Hi Corey,
That seems like it might be a bug. The event should fire any time the description might change. But even so, it's probably not something we can change, since changing event firing is a very dangerous and potentially breaking change.
Are you deleting the row through the grid or directly on the data source?
If it's through the grid, then you should be able to work around this pretty easily:
private void ultraGrid1_AfterRowsDeleted(object sender, EventArgs e) { UltraGrid grid = (UltraGrid)sender; grid.Rows.Refresh(RefreshRow.FireInitializeRow, true); }
If you are deleting the rows through the data source, then you can basically do the same thing, but you will have to find a way to trap when the rows are deleted. Since you are doing it in code, it should not be too difficult, but you might have to use a BeginInvoke to avoid any timing issue.
Mike,
I am deleting/adding rows through the data source, and your suggestion does seem to work. However, in the OnInitializeGroupByRow handler, the count of items in the description string is still not correct, but the row count for the group is correct. So basically I can no longer trust the count in the description string and will have to customize the count as well by using the row count.
Thanks for the help,
So your code is pulling apart the Description string inside the InitializeGroupByRow event and the Description hasn't been updated yet?
I would probably build the string based on the properties of the grid, anyway. The Count property on the rows collection is more reliable.
But just for fun, I tried this out and it seems to work fine for me. The Description of the row shows the correct number of items inside InitializeGroupByRow when I do this. I tested it by deleting a row in a button click event and then immediately calling Refresh:
private void button1_Click(object sender, EventArgs e) { this.dt1.Rows[0].Delete(); this.ultraGrid1.Rows.Refresh(RefreshRow.FireInitializeRow); }
And then I just displayed the row's Description inside of InitializeGroupByRow.
private void ultraGrid1_InitializeGroupByRow(object sender, InitializeGroupByRowEventArgs e) { Debug.WriteLine(e.Row.Description); }
When I ran my app, I had 32 items in the list. My Debug.Writeline for this group shows the following:
columnName : value (31 items)
So that seems right.Of course, I only have 100 rows in my grid, so maybe this is a timing issue because you have more rows. If that is the case, then you should be able to work around it using a BeginInvoke.
private void button1_Click(object sender, EventArgs e) { this.dt1.Rows[0].Delete(); this.BeginInvoke(new MethodInvoker(this.FireInitializeRow)); } private void FireInitializeRow() { this.ultraGrid1.Rows.Refresh(RefreshRow.FireInitializeRow); }
Ok, thanks for the help!
Oh, yeah, now that I think about it, that makes perfect sense. The reason the count is off is because you set the Description property. Once you set it, it will never be automatically updated again. Your text takes precedence over the auto-generated description.
That's another reason why you should not do a replace or use the existing description as a basis for the new description - because the grid will never update that description again.
So you will need to build the description string based on the properties of the row.
That does look similar to what I am doing. One difference might be that I am first customizing the description when the grid loads and a particular column is grouped on.
e.Row.Description = e.Row.Description.Replace(textToReplace);
Then as you did above during a delete, I am looking again at the description with that same code and the count is off.