Datagridviewcombobox将不会保持下拉菜单 [英] Datagridviewcombobox Will Not Stay Dropdown
问题描述
我到处都找到了一些代码,并且能够提出一些代码来将DGVCombobox的样式更改为下拉列表,而不是下拉列表.它本身可以正常工作,但是当我在EditingControlShowing处理程序中添加更多代码以解决另一种控件类型(阻止用户在第3列的文本框中输入除十进制数字之外的任何内容)时,它会中断.当我在选择处理的文本框后选择另一个单元格时,DGVCombobox停止工作.如果我注释掉处理第3列文本框的代码,则处理组合框类型的代码将再次起作用.我缺少明显的东西吗?
I found some code here and there and was able to come up with some code to change the style of the DGVCombobox to a dropdown instead of droplist. It works fine by itself, but when I add more code in the EditingControlShowing handler to address another control type (stop user from entering anything but a decimal number in a textbox in column 3) it breaks. When I select another cell after selecting the handled textbox, the DGVCombobox stops working. If I comment out the code to handle column 3 textbox, the code for handling the combobox type works again. Am I missing something obvious?
'Allow user to enter new values for ALL DataGridViewComboBox controls in the DataGridView
If (TypeOf e.Control Is DataGridViewComboBoxEditingControl) Then
Dim cmb As DataGridViewComboBoxEditingControl = CType(e.Control, DataGridViewComboBoxEditingControl)
If Not cmb Is Nothing Then
cmb.DropDownStyle = ComboBoxStyle.DropDown
End If
End If
' stop user from entering anything but a decimal number with 2 decimal places into column 3
If (TypeOf e.Control Is DataGridViewTextBoxEditingControl) Then
If (JobComponentsDataGridView.CurrentCell.ColumnIndex = 2) Then
Dim textBox As TextBox
textBox = CType(e.Control, TextBox)
If (Not (textBox) Is Nothing) Then
AddHandler textBox.KeyPress, AddressOf DataGridViewTextColumn_KeyPress_NumericOnly
RemoveHandler Me.JobComponentsDataGridView.EditingControlShowing, AddressOf JobComponentsDataGridView_EditingControlShowing
End If
End If
End If
推荐答案
尝试此链接.....
http://www.rustemsoft.com/vbbegin.asp
Try this link.....
http://www.rustemsoft.com/vbbegin.asp
我不知道使用DGVcombobox是否太慢而无法正常运行该程序.你同意我的观点吗?
I wonder if using DGVcombobox is too slow that can''t run the program normally . Do you agree with me ?
这篇关于Datagridviewcombobox将不会保持下拉菜单的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!