简体   繁体   中英

Remember the order in which DataGridViewRows are selected?

I was wondering if it is possible to remember the order in which rows are selected. I currently have a DataGridView which is bound to a collection of items. It appears that the OnRowStateChanged fires incorrectly during the process of selecting rows using the keyboard.

Any ideas?

I am using SelectionMode.FullRowSelect, it appears that the current selection is lost during the selection of a new row.

Thanks Rohan

just verified, the first selected rows are at the end of the list:

private void button1_Click(object sender, EventArgs e)
{

    for (int i = dataGridView1.SelectedRows.Count - 1; i >= 0; --i)
    {
        var r = dataGridView1.SelectedRows[i];
        MessageBox.Show(r.Cells[0].Value.ToString());
    }

 }

You could capture the RowEnter and RowLeave events to track the order in which rows are visited. The argument to these handlers contains event args with the row index. In the body of the handler, you could use a linked list as a FIFO queue to follow the order in which the rows are visited.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM