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

mod rewrite - Doing external redirect. .htaccess NS flag not working. How to achieve similar results? -

mysql - How to insert just year and month into date field? -