关于datagridview的dataerror事件如何定位cell的问题
datagridview的dataerror事件如何定位是哪个cell出现问题
比如加载某个数据的时候,我希望能在datagridview定位到这个cell,显示红色.
我在dataerror里面用
DataGridView1.CurrentCell.Style.BackColor = Color.Red
不能实现.
谢谢各位提供建议!
以下是msdn里面的dataerror代码
Visual Basic 複製程式碼 Private Sub DataGridView1_DataError(ByVal sender As Object, _ByVal e As DataGridViewDataErrorEventArgs) _Handles DataGridView1.DataError MessageBox.Show("Error happened " _ & e.Context.ToString()) If (e.Context = DataGridViewDataErrorContexts.Commit) _ Then MessageBox.Show("Commit error") End If If (e.Context = DataGridViewDataErrorContexts _ .CurrentCellChange) Then MessageBox.Show("Cell change") End If If (e.Context = DataGridViewDataErrorContexts.Parsing) _ Then MessageBox.Show("parsing error") End If If (e.Context = _ DataGridViewDataErrorContexts.LeaveControl) Then MessageBox.Show("leave control error") End If If (TypeOf (e.Exception) Is ConstraintException) Then Dim view As DataGridView = CType(sender, DataGridView) view.Rows(e.RowIndex).ErrorText = "an error" view.Rows(e.RowIndex).Cells(e.ColumnIndex) _ .ErrorText = "an error" e.ThrowException = False End IfEnd Sub
Private Sub DataGridView1_DataError(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DataGridViewDataErrorEventArgs) Handles DataGridView1.DataError DataGridView1.Rows(e.RowIndex).Cells(e.ColumnIndex).Style.BackColor = Color.Red End Sub