Quantcast
Viewing all articles
Browse latest Browse all 12583

The value of DataGridViewRow.Tag is lost after sorting

I'm facing one problem with DataGridViewRow.Tag. I set some values to DataGridViewRow.Tag. Then, I get those values whenever it is necessary. but when I do sorting the GridView by clicking the header of Girdview, all values which was set are gone...

The following is my sample code..

Filling the data to DataView

private void Form1_Load(object sender, EventArgs e){
 this.employeesTableAdapter.Fill (this.employeeMgmtDataSet.Employees);       
}


Setting the value to DataGridViewRow.Tag
private void button1_Click(object sender, EventArgs e){
  foreach ( DataGridViewRow dr in dataGridView1.Rows ){
    dr.Tag   = "Michael Sync";
  }
}

Getting the value from DataGridViewRow.Tag

private void button2_Click(object sender, EventArgs e){
  foreach ( DataGridViewRow dr in dataGridView1.Rows ){
   Console.WriteLine (dr.Tag.ToString ());
  }
}

it works fine before sorting.. but Tag become "null" after sorting.. Why is it happening like that? Any idea would be appreciated. Thanks in advance..

Viewing all articles
Browse latest Browse all 12583

Trending Articles