简体   繁体   English

还记得选择DataGridViewRows的顺序吗?

[英]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. 我目前有一个绑定到项目集合的DataGridView。 It appears that the OnRowStateChanged fires incorrectly during the process of selecting rows using the keyboard. 在使用键盘选择行的过程中,似乎OnRowStateChanged错误地触发了。

Any ideas? 有任何想法吗?

Edit 编辑

I am using SelectionMode.FullRowSelect, it appears that the current selection is lost during the selection of a new row. 我正在使用SelectionMode.FullRowSelect,似乎在选择新行期间丢失了当前选择。

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. 您可以捕获RowEnter和RowLeave事件以跟踪访问行的顺序。 The argument to these handlers contains event args with the row index. 这些处理程序的参数包含带有行索引的事件args。 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. 在处理程序的主体中,您可以将链接列表用作FIFO队列,以遵循访问行的顺序。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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