[英]VB.NET DataGridView - doesn't set cell.backgroundcolor
[英]Can't access Cell data in DataGridView VB.Net
我在Visual Studio 2017中有一個使用VB.NET的項目,該項目使用DataTable填充了DataGridView。 數據在網格中看起來很好,但是當我嘗試訪問SelectionChanged事件中的單元格值時,總是得到Nothing。 這是事件:
Private Sub grdBooks_SelectionChanged(sender As Object, e As EventArgs) Handles grdBooks.SelectionChanged
If Not grdBooks.CurrentRow Is Nothing Then
If grdBooks.CurrentRow.Index > -1 Then
Dim X As String = grdBooks.Rows(0).Cells(0).Value
Dim Y = grdBooks(0, 0).Value
UpdateEditPanel(False)
End If
End If
End Sub
因此,X和Y應該從位置0,0處的網格中給我相同的值,但事實並非如此。 我以前在其他項目中使用過此功能。 有人有什么想法嗎?
謝謝,科林
我也對這篇文章感到困惑,但我希望這可以幫助您解決問題。 可能的解決方案#1
Dim X As String = DataGridView1.SelectedRows(0).Cells(0).Value.ToString
要么
Dim X As String = DataGridView1.SelectedRows(0).Cells(0).Value.ToString()
如果您能夠提供更多代碼,我相信我們可以解決此問題。 干杯。
如果只想單擊網格中的單元格,請嘗試以下操作:
Private Sub grdBooks_CellContentClick(sender As Object, e As DataGridViewCellEventArgs) Handles grdBooks.CellContentClick
Dim selectedRow As DataGridViewRow
selectedRow = grdBooks.Rows(e.RowIndex)
Dim x as string = selectedRow.Cells(0).Value.ToString()
End Sub
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.