Hi everyone,
i have a problem. I am working on a c# windows application that requires me to swap row values in a datagrid. Let's say for example, A column is with names is displayed in the datagrid, what I want to do is take row 1 (jack) and exchange it with row 15(paul) and exchange the values within the actual cells.
Here's what I tried:
results, I get a compile error when I try this method
Any suggestions?
Please help
i have a problem. I am working on a c# windows application that requires me to swap row values in a datagrid. Let's say for example, A column is with names is displayed in the datagrid, what I want to do is take row 1 (jack) and exchange it with row 15(paul) and exchange the values within the actual cells.
Here's what I tried:
Code:
void swap_datagrid_values()
{
int ct;
int last = dataGridView1.RowCount;
string temp;
for(int i=0; i<dataGridView1.RowCount; i++)
{
foreach (DataGridViewRow row in dataGridView1.SelectedRows)
{
temp = dataGridView1.SelectedCells[i].ToString();
dataGridView1.SelectedCells[i].ToString() = dataGridView1.SelectedCells[last].ToString();
dataGridView1.SelectedCells[last].ToString() = temp;
last--;
}
}
}
Any suggestions?
Please help
Comment