C#winform问题 datagridview中combobox选项改变触发事件用哪个方法
2个回答
展开全部
给你个VB的写法,自己改成C#的。
'下面这个保证一旦ComboBox数据改变会提交给事件
Private
Sub
DataGridView1_CurrentCellDirtyStateChanged(ByVal
sender
As
Object,
ByVal
e
As
System.EventArgs)
Handles
DataGridView1.CurrentCellDirtyStateChanged
If
DataGridView1.IsCurrentCellDirty
Then
DataGridView1.CommitEdit(DataGridViewDataErrorContexts.Commit)
End
If
End
Sub
’这里响应事件
Private
Sub
DataGridView1_CellValueChanged(ByVal
sender
As
Object,
ByVal
e
As
System.Windows.Forms.DataGridViewCellEventArgs)
Handles
DataGridView1.CellValueChanged
If
e.ColumnIndex
=
1
AndAlso
e.RowIndex
>
-1
Then
MessageBox.Show(DataGridView1.Rows(e.RowIndex).Cells(1).Value)
End
If
End
Sub
'下面这个保证一旦ComboBox数据改变会提交给事件
Private
Sub
DataGridView1_CurrentCellDirtyStateChanged(ByVal
sender
As
Object,
ByVal
e
As
System.EventArgs)
Handles
DataGridView1.CurrentCellDirtyStateChanged
If
DataGridView1.IsCurrentCellDirty
Then
DataGridView1.CommitEdit(DataGridViewDataErrorContexts.Commit)
End
If
End
Sub
’这里响应事件
Private
Sub
DataGridView1_CellValueChanged(ByVal
sender
As
Object,
ByVal
e
As
System.Windows.Forms.DataGridViewCellEventArgs)
Handles
DataGridView1.CellValueChanged
If
e.ColumnIndex
=
1
AndAlso
e.RowIndex
>
-1
Then
MessageBox.Show(DataGridView1.Rows(e.RowIndex).Cells(1).Value)
End
If
End
Sub
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询