danasegarane
Active member
- Joined
- Jun 14, 2006
- Messages
- 41
- Programming Experience
- Beginner
Dear All,
I am placing a combo box in datagrid view cell.I am using this code.The problem is that when i press the tab key the entered values get into the
combo box dropdown list.But when I press the Enter key unfortunately not
How can I solve this problem
Thanks in advance
Dana
I am placing a combo box in datagrid view cell.I am using this code.The problem is that when i press the tab key the entered values get into the
combo box dropdown list.But when I press the Enter key unfortunately not
VB.NET:
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
DataGridViewColumns.Add("Name", "Name")
DataGridViewColumns.Add("Age", "Age")
DataGridViewColumns.Add("Phone", "Phone")
Dim comboboxcol As New DataGridViewComboBoxColumn
comboboxcol.HeaderText = "Type"
comboboxcol.Items.Add("Type A")
comboboxcol.Items.Add("Type B")
comboboxcol.Items.Add("Type C")
comboboxcol.Items.Add("Type D")
DataGridViewColumns.Add(comboboxcol)
End Sub
Private Sub DataGridView1_EditingControlShowing(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewEditingControlShowingEventArgs) Handles DataGridViewEditingControlShowing
Dim combocol As DataGridViewComboBoxColumn = DataGridViewColumns(3)
If (DataGridViewCurrentCellAddress.X = combocol.DisplayIndex) Then
Dim cbbox As ComboBox = e.Control
If cbbox IsNot Nothing Then
cbbox.DropDownStyle = ComboBoxStyle.DropDown
End If
End If
End Sub
Private Sub DataGridView1_CellValidating(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DataGridViewCellValidatingEventArgs) Handles DataGridViewCellValidating
Dim cbcol As DataGridViewComboBoxColumn = DataGridViewColumns(3)
If (e.ColumnIndex = cbcol.DisplayIndex) Then
If Not cbcol.Items.Contains(e.FormattedValue) Then
cbcol.Items.Add(e.FormattedValue) 'Errror Line
End If
End If
End Sub
How can I solve this problem
Thanks in advance
Dana