winforms - Current selected value in DataGridView using C# -


i'm trying current selected value datagridview

messagebox.show(""+datagridview1.selectedcells.tostring()+"") 

but never shows selected value.

it shows

system.windows.forms.datagridviewselectedcellcollection

you should way

messagebox.show(datagrdiview1.selectedcells[0].value.tostring()); 

try access value or text of single cell, , not entire collection

you can iterate through entire selectedcells collection

 string text;  foreach (datagridviewcell cell in datagridview1.selectedcells)  {      //messagebox.show(cell.value.tostring());      text +=cell.value.tostring();  }  messagebox.show(text); 

Comments

Popular posts from this blog

sql - VB.NET Operand type clash: date is incompatible with int error -

SVG stroke-linecap doesn't work for circles in Firefox? -

python - TypeError: Scalar value for argument 'color' is not numeric in openCV -