If I select more then one cell in a DataGridView, how can I get (in a MsgBox) the value of the cell with the highest ColumnIndex (amongst the selected) ?
List<string> a = new List<string>();
foreach (DataGridViewCell cell in dgvC.SelectedCells)
{
a.Add(cell.Value.ToString());
}
So, I need the rest of cells in a row to populate by repeating the list made by selecting some cells.
One way to do it is to use linq to order the collection of selected cells by ColumnIndex and then get the first one.
You should note that depending on how the user made the selection (top to bottom or bottom to top) you will either get the value from the first row or the last row. If that matters you should also order by RowIndex
Another way is to examine the first and last cells in the collection and compare the indexes . We need to look at both because depending on how the user made the selection the one with the greater column index will change.
Note: you should check for Null values if AllowUsersToAddRow is true