简体   繁体   English

使用复选框选择Datagrid行

[英]Select Datagrid Rows with Checkbox

I'm using visual studio 2008 .net 3.5 (windows application) I have a Devexpress datagridview and I want to select multiple rows using checkboxes . 我正在使用Visual Studio 2008 .net 3.5(Windows应用程序),我有一个Devexpress datagridview,我想使用复选框选择多个行。 I have found this Code in Devexpress Forum.( http://www.devexpress.com/Support/Center/p/E1271.aspx ) it works very good , but I dont know how to recognize which rows are selected ! 我在Devexpress论坛中找到了此代码。( http://www.devexpress.com/Support/Center/p/E1271.aspx )它的效果很好,但是我不知道如何识别选择了哪些行!

I want user select some rows with checkboxes and then copy the selected rows to another datagrid. 我希望用户使用复选框选择一些行,然后将所选行复制到另一个数据网格。 thank you 谢谢

You might be looking for: 您可能正在寻找:

yourDataGridView.SelectedRows

which returns a DataGridViewSelectedRow collection. 它返回一个DataGridViewSelectedRow集合。 You can iterate it through a foreach loop, like: 您可以通过foreach循环对其进行迭代,例如:

foreach (selectedDataGridViewRow row in yourDataGridView.SelectedRows)
{
    // do what you got to do with the selected row...
}

As I understand the code sample from DevExpress there's the member selection that stores the selected rows. 据我了解,DevExpress的代码示例包含用于存储选定行的成员选择 The following two parts of the sample seem to approve that: 该示例的以下两个部分似乎对此表示赞同:

protected ArrayList selection;

//...

void SelectRow(int rowHandle, bool select, bool invalidate) {
    if (IsRowSelected(rowHandle) == select) return;
    object row = _view.GetRow(rowHandle);
    if (select)
        selection.Add(row);
    else
        selection.Remove(row);
    if (invalidate) {
       Invalidate();
    }
}

Have a look at this member, I think that's what you are searching. 看看这个成员,我想这就是您要寻找的。

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

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