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

android - Why am I getting the message 'Youractivity.java is not an activity subclass or alias' -

python - How do I create a list index that loops through integers in another list -

c# - “System.Security.Cryptography.CryptographicException: Keyset does not exist” when reading private key from remote machine -