![](/img/trans.png)
[英]how to retrieve the selected row cell value if it is visible property is false in gridview?
[英]How to retrieve a last row cell value
使用VB.Net
我想檢索最后一行的單元格值
數據網格
01 Rajan
02 Vijayan
03 Suresh
嘗試過這樣的代碼
For i As Integer = 0 To datagrid1.RowCount - 1
textbox1.text = datagrid1.currentrow.Cells(0).Value 'current row
textbox2.text = datagrid1.row(i).Cells(0).Value 'last row
Next
最后一行顯示為空
預期產量
textbox2.text = 03
我的代碼有什么問題,需要vb.net代碼。
dataGridView1.Rows[dataGridView1.RowCount - 1].Cells[0].Value.ToString();
.rows是一個集合,並且也像數組一樣工作,數組的索引計數從0到N-1
您應該可以使用linq; dataGridView1.Rows.Cast<DataGridViewRow>().LastOrDefault()
將為您提供最后一行;如果不存在任何行,則為null。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.