VB.NET DataGridViewComboBoxCell 选择其中一行中的Item的事件
如上图,我在第二行的List_Vonder中选择了其中一项(例如Dupont),怎么写这个事件,我想在另外的单独一个label中显示当前行的行数(2),和在List_Vo...
如上图,我在第二行的List_Vonder中选择了其中一项(例如Dupont),怎么写这个事件,我想在另外的单独一个 label中显示 当前行的行数(2),和在List_Vonder选择的那项(Dupont).
以下是截取的添加 DataGridViewComboBoxCell 的一段代码
Dim dtgCol As New DataGridViewComboBoxCelldtgCol.DataSource = ListBox_temp.ItemsDataGV_Souce.Rows(i).Cells(7) = dtgCol
琢磨出来了,用以下的方法,很简单.
Private Sub DGV_Proc_CurrentCellDirtyStateChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles DataGV_Souce.CurrentCellDirtyStateChanged
If DataGV_Souce.IsCurrentCellDirty Then
DataGV_Souce.CommitEdit(DataGridViewDataErrorContexts.Commit)
MsgBox("第" & DataGV_Souce.CurrentRow.Cells(0).Value & " Vendor:" & DataGV_Souce.CurrentRow.Cells(7).Value)
End If
End Sub 展开
以下是截取的添加 DataGridViewComboBoxCell 的一段代码
Dim dtgCol As New DataGridViewComboBoxCelldtgCol.DataSource = ListBox_temp.ItemsDataGV_Souce.Rows(i).Cells(7) = dtgCol
琢磨出来了,用以下的方法,很简单.
Private Sub DGV_Proc_CurrentCellDirtyStateChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles DataGV_Souce.CurrentCellDirtyStateChanged
If DataGV_Souce.IsCurrentCellDirty Then
DataGV_Souce.CommitEdit(DataGridViewDataErrorContexts.Commit)
MsgBox("第" & DataGV_Souce.CurrentRow.Cells(0).Value & " Vendor:" & DataGV_Souce.CurrentRow.Cells(7).Value)
End If
End Sub 展开
1个回答
展开全部
在datagridview的EditingControlShowing事件中给DataGridViewComboBoxCell绑定selectindexchanged事件,类似如下方式:(是用C#写的,改成vb.net就可以了)
private void dataGridView1_EditingControlShowing(object sender, DataGridViewEditingControlShowingEventArgs e)
{
ComboBox cb = e.Control as ComboBox;
if (cb != null)
{
cb.SelectedIndexChanged -= new EventHandler(cb_SelectedIndexChanged);
cb.SelectedIndexChanged += new EventHandler(cb_SelectedIndexChanged);
}
}
void cb_SelectedIndexChanged(object sender, EventArgs e)
{
MessageBox.Show("changed");
}
private void dataGridView1_EditingControlShowing(object sender, DataGridViewEditingControlShowingEventArgs e)
{
ComboBox cb = e.Control as ComboBox;
if (cb != null)
{
cb.SelectedIndexChanged -= new EventHandler(cb_SelectedIndexChanged);
cb.SelectedIndexChanged += new EventHandler(cb_SelectedIndexChanged);
}
}
void cb_SelectedIndexChanged(object sender, EventArgs e)
{
MessageBox.Show("changed");
}
追问
自己搞定了,不过还是谢谢你
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询