i have a datagridview which is not related with dataTable.
and i want to swap for example 1st and 10th rows in datagridview.
i use this code for it
int row_1 = 1;
int row_10 = 10;
for(int i=0;i<grid.ColumnCount;i++)
{
string temp = grid.Rows[row_1].Cells[i].Value.ToString();
grid.Rows[row_1].Cells[i].Value = grid.Rows[row_10].Cells[i].Value.ToString();
grid.Rows[row_10].Cells[i].Value = temp;
}
but i want to know is there any simple way to do this??
Value.ToString()
and so on, just store the Value in an object. That will be generic, unlike your code, which only works with strings. – Danielledaniels