用vb2005编程,datagrideview实现下拉框,绑定数据表,表中有编号和名称,当我在下拉框中选择编号后,在其他列马上显示编号相对应的名称

'* 展开Combobox列时     Private Sub Me_EditingControlShowing(ByVal sender As Object, ByVal e As DataGridViewEditingControlShowingEventArgs) Handles Me.EditingControlShowing         If InStr(e.Control.ToString, "DataGridViewComboBoxEditingControl", CompareMethod.Text) > 0 Then             Dim DgComboBox As ComboBox = CType(e.Control, ComboBox)             RemoveHandler DgComboBox.SelectionChangeCommitted, AddressOf ComboBox_SelectedIndexChanged  '// 防止多次绑定事件,多次绑定会让一个事件被多次执行             AddHandler DgComboBox.SelectionChangeCommitted, AddressOf ComboBox_SelectedIndexChanged         End If     End Sub     '     '* 选择列中的Combobox时写入值:     Private StopWrtieCurrentChangeComboboxIndex As Boolean = False '// 用来阻止,将DataTable的值写入数据源时,同时又触发ComboBox_SelectedIndexChanged()     Private Sub ComboBox_SelectedIndexChanged(ByVal sender As Object, ByVal e As EventArgs)         If StopWrtieCurrentChangeComboboxIndex = True Then  '//             Return         End If         Dim DgComboBox As ComboBox = CType(sender, ComboBox)         If DgComboBox.DataSource Is Nothing Then                                                        '// 1.绑定到数组:不需设置             'Me.CurrentCell.Value = Trim(DgComboBox.SelectedItem)         ElseIf InStr(DgComboBox.DataSource.GetType.ToString, "DataTable", CompareMethod.Text) > 0 Then  '// 2.绑定到System.Data.DataTable:根据映射数组设置来填写数据             StopWrtieCurrentChangeComboboxIndex = True             If InStr(Me.DataSource.GetType.ToString, "BindingSource", CompareMethod.Text) > 0 Then                 Dim GridBindSource As BindingSource = Me.DataSource                 GridBindSource.Current.item("Field1") = DgComboBox.Items(DgComboBox.SelectedIndex).item("FieldValue")                 GridBindSource.EndEdit()             End If             StopWrtieCurrentChangeComboboxIndex = False         End If     End Sub
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值