Visual Studio Development Bookmark and Share   
 index > Visual Basic Express Edition > DataGridViewComboBoxColumn
 

DataGridViewComboBoxColumn

hi, i have a simple datagridview bound to a bindingsource which is bound to a datatable. i've replaced one of the standard textbox columns with datagridviewcomboboxcolumn which is where  my problem begins. if i begin typing into the last datagridviewcomboboxcolumn row in the datagridview, and i don't worry about the editingcontrolshowing event, i can easily select a value from the datagridviewcombobocolumn and automatically a new row appears in the datagridview every time, all good.

with the code below i now address the editingconrolshowing event, as i want to add items to the datagridviewcombobocolumn if they don't exist. now if i begin typing into the last row in the datagridviewcomboboxcolumn, a new row does not automatically appear and even if i type the exact same text (even the entire word) as one of the existing combobox values and press enter this value isn't selected. the second time i try this it generally works.

I've also noticed that the first time i try to update a value at another row (not necessarily the last row) the newly selected value doesn't appear in the datagridviewcombobocolumn, also the second time i try this it generally works.

bald.

 

Private Sub dgv_workpackdata_EditingControlShowing(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewEditingControlShowingEventArgs) Handles dgv_workpackdata.EditingControlShowing

If (TypeOf e.Control Is ComboBox) Then

Dim combo As DataGridViewComboBoxEditingControl= CType(e.Control, DataGridViewComboBoxEditingControl)

If (combo IsNot Nothing) Then
combo.DropDownStyle = ComboBoxStyle.DropDown
End If

End If

 

Private Sub dgv_workpackdata_CellValidating(ByVal sender As Object, ByVal e As  ystem.Windows.Forms.DataGridViewCellValidatingEventArgs) Handles dgv_workpackdata.CellValidating

Dim drv As DataRowView

Select Case e.ColumnIndex

Case 10

drv = wp_data.bs_workpackdata.List.Item(wp_data.bs_workpackdata.List.Count - 1)
drv.BeginEdit()
drv.Item(
"ISOMETRIC") = e.FormattedValue
drv.EndEdit()

End Select

End Sub

End Su

mrrobrussell  Monday, March 05, 2007 5:40 PM

workaround, i've attached an event handler to theediting control'sleave event. event code below, simply updates the combobox in the datagridview when fired.

Private Sub dgv_workpackdata_EditingControlShowing(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewEditingControlShowingEventArgs) Handles dgv_workpackdata.EditingControlShowing

RemoveHandler e.Control.KeyPress, AddressOf dgv_workpackdata_touppercase
AddHandler e.Control.KeyPress, AddressOf dgv_workpackdata_touppercase

If (TypeOf e.Control Is ComboBox) Then
Dim cmb_editingcontrol As DataGridViewComboBoxEditingControl = CType(e.Control, DataGridViewComboBoxEditingControl)

If (cmb_editingcontrol IsNot Nothing) Then
cmb_editingcontrol.AutoCompleteMode = AutoCompleteMode.SuggestAppend
cmb_editingcontrol.DropDownStyle = ComboBoxStyle.DropDown

RemoveHandler cmb_editingcontrol.Leave, AddressOf dgv_workpackdata_combo_leave
AddHandler cmb_editingcontrol.Leave, AddressOf dgv_workpackdata_combo_leave

End If

End If

End Sub

'event handler for combo leave
Sub dgv_workpackdata_combo_leave(ByVal o As Object, ByVal e As System.EventArgs)
Dim cmb_editingcontrol As DataGridViewComboBoxEditingControl = CType(o, DataGridViewComboBoxEditingControl)
'force the datagridviewcombocolumn value
dgv_workpackdata.Item(intcol, introw).Value = cmb_editingcontrol.Text
End Sub

'event handler for uppercase input
Sub dgv_workpackdata_touppercase(ByVal o As [Object], ByVal e As KeyPressEventArgs)
e.KeyChar = UCase(e.KeyChar)
Debug.Print(e.KeyChar.ToString)
End Sub

mrrobrussell  Tuesday, March 06, 2007 7:05 AM

You can use google to search for other answers

Custom Search

More Threads

• Icon maker?
• How to compare dataset (or datatable) info for use with radio buttons?
• VB shuts down without errors
• Notepad.NET Beta Released: Feedback Needed.
• Print page
• WebBrowser - possible to get XY pos of an image?
• Navigate cells without capturing
• compare many digit variable???
• Data reapeter
• Copy,Cut and Paste