简体   繁体   中英

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 . 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 !

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. You can iterate it through a foreach loop, like:

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. 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.

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