简体   繁体   中英

c# - Multiple Select on Datagridview using BindingSource

I know that to get single selected row on a datagridview using a BindingSource is this code:

BindingSource.Current

DataGridViewRow.DataBoundItem contains the 'business' object it is bound to. This sample:

DataRow row = (dataGridView1.SelectedRows[0].DataBoundItem as DataRowView).Row;

Guess it might be too late, but here is one solution...

var myListOfYOURBJECTTYPE = dataGridViewEstados.Rows
                                        .Cast<DataGridViewRow>()
                                        .Where(r => r.Selected == true)
                                        .Select(d => (YOURBJECTTYPE)d.DataBoundItem)
                                        ToList();

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