Click here to Skip to main content
16,016,425 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello All,

I am using the following code to allow drop down in a DataGridViewComboBoxColumn:

VB
Private Sub DataGridView1_CellEnter(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles DataGridView1.CellEnter

        DataGridView1.BeginEdit(True)
        If varMode = 1 Or varMode = 2 Then
            If DataGridView1.Rows(e.RowIndex).Cells(ddlGroupUnderingrid.Name).Selected = True Then
                DirectCast(DataGridView1.EditingControl, DataGridViewComboBoxEditingControl).DroppedDown = True
            End If
        End If

    End Sub


Problem is when the data is prefilled into the grid and i press down arrow to select another option from items of combobox, the selection moved to next row and on pressing tab the 2nd row next cell is selected instead of 1 row.

Pls ask for any more details required.

Thanks in advance
Posted

1 solution

I have checked your code there is no problem which you have wrote.. I have only remark the line of varMode because I have not understand why you have use this..

VB
Private Sub DataGridView1_CellEnter(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles DataGridView1.CellEnter
        DataGridView1.BeginEdit(True)
        'If varMode = 1 Or varMode = 2 Then
        If DataGridView1.Rows(e.RowIndex).Cells(Me.ComboColumn6.Name).Selected = True Then
            DirectCast(DataGridView1.EditingControl, DataGridViewComboBoxEditingControl).DroppedDown = True
        End If
        'End If
    End Sub
 
Share this answer
 
Comments
atul sharma 5126 7-Mar-14 3:36am    
hi sohail. Thanks for the reply.
The varmode is a variable i have created based on users selection.

The issue is coming when we enter the grid. The first column itself is the combobox with dropdown. The dropdown works but on trying to make selection through arrow the selection moves to row number 2 column 1.
If i come again to row1,column1 then their is no issue.

So, the problem lies between the enter events of grid and cell.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900