+ 2
How can I access datagridview value from another winform?
I want to access a DataGridView from another form. I just want to get a value from DataGridView and show it in a textbox located in another form. When i click button1, textbox1 should have the value of row[0] cell[0] (which is "1") but instead i get this Error: An unhandled exception of type 'System.ArgumentOutOfRangeException': Index was out of range. Must be non-negative and less than the size of the collection. is there anything I'm not doing right? I made datagridview modifiers = public
1 ответ
+ 1
Please put the value you need in a property. It is considered bad practice to use ui-controls to pass data between forms.
pseudo code:
button_click
cellvalue = datagrid.cells [0][0]
dataform secondform = new dataform ();
secondform.CellValue = cellvalue;
secondform.show ();
in the show of secondform
there is some code like
textbox1.text = cellvalue;