在 tha datagridview 中有五列作为
1 - 产品 ID 2- 产品名称 3- 描述 4- 价格,第五个是
选择国家,即 comboboxcolumn
DataGridView1.Columns.Add("ID", "Product ID")
DataGridView1.Columns.Add("Name", "Product Name")
DataGridView1.Columns.Add("Description", "Description")
DataGridView1.Columns.Add("Price", "Price")
Dim datagridviewcol As New DataGridViewComboBoxColumn
datagridviewcol.Items.Add("Pak")
datagridviewcol.Items.Add("KUI")
datagridviewcol.Name = "Select"
DataGridView1.Columns.Add(datagridviewcol)
我在 datagridview 编辑控件中添加处理程序 selectedindexchanged 显示如下
Private Sub DataGridView1_EditingControlShowing(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DataGridViewEditingControlShowingEventArgs) Handles DataGridView1.EditingControlShowing
If Me.DataGridView1.CurrentCell.ColumnIndex = 4 Then
Dim cb As ComboBox = CType(e.Control, ComboBox)
AddHandler cb.SelectedIndexChanged, AddressOf ComboBox_SelectedIndexChanged
End If
End Sub
selectedindexchanged 事件如
Private Sub ComboBox_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs)
If CType(sender, ComboBox).SelectedIndex = 0 Then
MessageBox.Show("PAK")
Else
MessageBox.Show("KUI")
End If
End Sub
它运行良好,但如果您在 datagridview 行#4 上,那么如果您从第 15 行选择“PAK”,则消息框会提示您 4 次,然后消息框将提示 15 次,我只需要提示 1 次。
帮我。因此,与行无关,消息框显示 1 次而不是行号的次数。