c# - Get object associated with selected rows in DataGridView -


i have datagridview bound array of objects.

list<node> nodes = getnodelist();  m_grid.datasource = nodes; 

i handle selectionchanged event.

in handler selectionchanged event want access selected objects.

all seem able access value each cell in grid rather overall object associated row.

void onselectionchanged( object sender, eventargs e ) {     foreach ( dataviewgridrow row in m_grid.selectedrows )     {         /* here want able access node object associated row*/     } } 

i'm sure must possible can't figure out. row index , array seems bit hacky.

try this...

datagridviewselectedrowcollection rows = mydatagridview.selectedrows; foreach (datagridviewrow row in rows) {    datarow myrow = (row.databounditem datarowview).row;    // datarow } 

Comments

Popular posts from this blog

linux - Mailx and Gmail nss config dir -

c# - Is it possible to remove an existing registration from Autofac container builder? -

php - Mysql PK and FK char(36) vs int(10) -