views:

153

answers:

1

Is there a way to keep the tags from being nulled as soon as I sort the grid?

If not, is the Tag property actually useful for anything except non-databound usage?

+3  A: 

Based on you last question, you are setting the Tag of DataGridViewRow objects. And they might very well be re-created during a Sort operation. Use reflector to make sure, but I would start looking for a workaround.

In general, the Tag property is a last resort.

You could use a Dictionary<object, object> to couple your data to the dgvr.DataBoundItem as key.

Henk Holterman
I am, and it looks like you're right. If is DataSource null DataGridView.Sort() calls an internal Sort method on the Rows object. If DataSource has a value it calls the Sort method on the dataConnection member. That disappears into a ratsnest of interfaces; but I assume it eventually ends up somewhere in DataTable and ends up recreating the rows. Times like this make me nostolgic for MFC where I could trace into the framework at runtime and confirm if the rows were getting replaced by looking at pointer addresses...
Dan Neely
The DataRows in the DataTable are certainly not recreated (they end up as the DataBoundItem in the dgvr). Try using them a little more.
Henk Holterman
To Clarify I was referring to the DataGridViewRows that have the Tag property that is getting wiped out.
Dan Neely