點選 DataGridView 的表頭(Header)會錯誤
錯誤訊息(Error Msg):
並未將物件參考設定為物件的執行個體
Private Sub DataGridView1_SelectionChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles DataGridView1.SelectionChanged
'出錯的Code
If DataGridView1.CurrentRow.Index <> -1 Then
'do something
End If
'改成物件是否 Nothing
If DataGridView1.CurrentRow IsNot Nothing Then
'do something
End If
End Sub
或改成
'確定是否點選到DataGridView的某行資料列 [C#]
if (this.DataGridView.SelectedRows.Count != 0) {}
DataGridView - EditOnEnter
DataGridView 控制項 (Windows Form)
沒有留言:
張貼留言