Click here to Skip to main content
16,020,673 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hi every body i have a strange problem in my grid view when i fill my first row with data and move to the second row and after edit the second row and leave the row the data changed to the same as the previous row and so on all row which is edit change to the previous row how can i solve this problem this problem happened when i move with table enter arrows of keyboard


Edit: from comments

this my my code
C#
if (dataGridView1.Rows[e.RowIndex].Cells[1].Value != null)
{
  string cellValue = dataGridView1.Rows[e.RowIndex].Cells[1].Value.ToString();
  if (!string.IsNullOrEmpty(cellValue))
  {
    _bar = cellValue;
    PopulateColumns();
    dataGridView1.Rows[e.RowIndex].Cells[2].Value = _proname;
    dataGridView1.Rows[e.RowIndex].Cells[3].Value = _price;
    dataGridView1.Rows[e.RowIndex].Cells[4].Value = _unit;
  }
}

i use PopulateColumns(); to access data from data table and pass it to the grid view where it equal dataGridView1.Rows[e.RowIndex].Cells[1].Value . when i use break-point it works correct if i stop break point it repeat the same data in each row despite the value of dataGridView1.Rows[e.RowIndex].Cells[1].Value is not the same ?
Posted
Updated 29-May-15 1:32am
v2
Comments
Andy Lanng 29-May-15 5:59am    
Please include the code you are using in furture
CHill60 29-May-15 6:00am    
What code do you have behind the datagrid?

1 solution

You need to initialize the new row in every loop:

C#
DataRow dr;

foreach(var row in myEnumerable)
{
   //Do this in every loop
   dr = new DataRow();

   //...Set column values

   dataTable.Rows.Add(dr);
}
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900