Goal
Currently looking to find a way how to select items from DataGridView and order it by the selected first at top.
Example
First selection by user:
Selected Column1 Column2
a 1
b 2
c 3
x d 4
Second selection...
Selected Column1 Column2
a 1
x b 2
c 3
x d 4
Third selection...
Selected Column1 Column2
x a 1
x b 2
c 3
x d 4
Order
4th row
2nd row
1st row
Summary
The 1st item selected by user was the 4th row, then the 2nd and lastly the 1st row.
Question
How can I get a list of the all rows in order as explained above?
Current Code
I created a checkbox column like so, so the user can see what they have selected.
DataGridViewCheckBoxColumn checkBoxColumn = new DataGridViewCheckBoxColumn();
checkBoxColumn.Name = "Selected";
checkBoxColumn.HeaderText = "Selected";
checkBoxColumn.ReadOnly = false;
productsView.Columns.Add(checkBoxColumn);
User then checks the checkbox to mark the selected records they desire, then they click a button to which opens another form.
But the order is mixed.
private void addBtn_Click(object sender, EventArgs e)
{
foreach (var row in checkedRows)
{
DateTime dateTime = dateText.Value;
string orderNumber = orderNumberText.Text;
SelectedProducts form = new SelectedProducts(dateTime, orderNumber);
form.ShowDialog();
}
}