开发者

Programmatically multiselect rows in WinForms DatagridView properly

Is it possible and if so, how, to programmatically select non-consecutive rows in a standard WinForms datagrid?

foreach (var selectableRowIndex in select开发者_StackOverflowableRowIndices)
{
    dataGridView.Rows[selectableRowIndex ].Selected = true;
}

... does work, but after setting the dataGridView's .CurrentCell Property via

dataGridView.CurrentCell = dataGridView.Rows[underlyingRowIndex].Cells[1];

all other rows get deselected.

What's the proper way to set the current row/cell and keep other rows selected?


I had same problem and my solution was to have a List<Int32> with the ids of the selected rows and to add or remove the ids as needed.


a quick and dirty solution would be:

-get the IDs of the currently selected rows
-change the current cell
-re-select the rows

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜