How to get cell value from datagridview using row index and column index in C #?
6 answers
I've tried the following in several places in my code: myvalue = dgvList.Rows [rowindex] .Cells [columnindex] .Value.ToString (); I am using it for the "dgvListSelectionChanged" event, but it only works once. It seems "on change has changed" fires, but the index is still not known at the time, as I get "Index out of range exception". I tested with lines 1-3 where column [0] is definitely defined. How can I solve this problem?
0
source to share
how to display db value to dvg in dgv cell exit event
str = "select pprice from product_tbl2 where name='" & Me.DataGridView1.CurrentRow.Cells(1).Value.ToString() & "'"
cmd.CommandText = str
MsgBox(cmd.CommandText)
cmd.Connection = cn
da = New SqlDataAdapter(cmd.CommandText, cn)
dt = New DataTable()
da.Fill(dt)
dvg.currentrows.cell(3) = dt.Rows(0)(0).ToString()
-1
source to share