[RESOLVED] Selected row to multi array
Hi all,
ANother newb question.
Is there a way to loop through the selected rows and store them in an array?
I've been working at it and have come up with this but it isnt working correctly.
2 Code:
int rCount = gridOffice.Rows.GetRowCount(DataGridViewElementStates.Selected);
if (rCount> 0)
{
String[,]s = new String[rCount,cCount];
for (int i = 0; i < rCount; i++)
{
for (int j = 0; j < 2; j++)
{
s[i,j] = gridOffice.Rows[gridOffice.SelectedCells[i].RowIndex].Cells[j].FormattedValue.ToString();
}
}
Thanks in advance
Re: Selected row to multi array
This shows you how to get each cell value from each selected row. What you do with those values is then up to you.
vb Code:
for (int row = 0; row < this.DataGridView1.SelectedRows.Count; row++)
{
for (int column = 0; column < this.DataGridView1.ColumnCount; column++)
{
MessageBox.Show(this.DataGridView1.SelectedRows[row].Cells[column].Value.ToString());
}
}