How to get cell value from datagridview using row index and column index in C #?
I have a datagridview dgvList . Then I want to get the cell value for a specific row and column without using the selectedRows property.
those.:
myvalue = dgvList[2nd row][1st column];
+6
Nandu PH
source
to share
6 answers
try it
myvalue =dgvList.Rows[rowindex].Cells[columnindex].Value.ToString();
+13
Pradnya bolli
source
to share
dgvList.Rows[INDEX].Cells[INDEX].Value
+3
Aseem Gautam
source
to share
dgvList[colIndex, rowIndex].Value
+1
Lakewind
source
to share
var myvalue =dgvList.Rows[columnindex, rowindex].Value;
0
Ramgy borja
source
to share
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
Kamal
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
kiran tamang
source
to share