Wednesday, 15 February 2012

c# - DataGridView selecting a specific row and retrieving all column values to an object array -



c# - DataGridView selecting a specific row and retrieving all column values to an object array -

i want perform operation on button click event , grid currentrow entire info passed object array

i have tried search through next links :

datagridview selecting specific row , retrieving values

getting info selected datagridview row , event?

but talking particular cell value

i tried perform code

datarowview currentdatarowview = (datarowview)grdglsearch.currentrow.databounditem; datarow row1 = currentdatarowview.row;

but currentdatarowview retrieving null

one of senior succesfully created generic property getselectedrow()

it works :

var object =grdglsearch.getselectedrow<t>();

and has definition

public t getselectedrow<t>() { if (this.currentrowindex == -1) { homecoming default(t); } homecoming (base.datasource bindinglist<t>)[this.currentrowindex]; }

but binded 1 main grid , want utilize property grids

i dont want info of particular column , want entire row info .. , dont want iteration perform ... there single liner operation ? please suggest if missing links

since showing 2 lines of code, not sure going on. first off, want entire row when click button. however, never state how current row beingness selected.

in order total selected row, must have selected cell. msdn documentation says on page datagridview.selectedrow. assuming user click cell, , want entire row. create variable hold selected row. when user clicks cell, automatically select row , save it. when button clicked, retrieve the saved row.

private datagridviewrow selectedrow { get; set; }

then have event when user clicks cell

private void grdglsearch_cellclick(object sender, datagridviewcelleventargs e) { selectedrow = grdglsearch.rows[e.rowindex]; }

finally, button click event

private void submitbtn_itemclick(object sender, itemclickeventargs e) { // target specific info var cellval1 = selectedrow.cells["specificcell1"].value; var cellval2 = selectedrow.cells["specificcell2"].value; }

c# winforms datagridview

No comments:

Post a Comment