views:

106

answers:

0

Is there a way to use a column of data from a DataTable to set the tag of a row automatically instead of having to iterate through each row in the DGV to manually assign it?

MyDataGridView.DataSource = GetDataTable();
foreach (DataGridViewRow dgvr in MyDataGridView.Rows)
{
 dgvr.Tag = (int)dgvr.Cells[0].Value;
}

I have a large amount of existing code (from when I was manually adding each row to the grid) that looks in the Tag value for the row ID. Partly this was done for consistency, not all of my grids show the ID at all, and partly because casting the tag to an int was faster then getting a value out of the row itself.