Click here to Skip to main content
15,922,309 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have used inbuild datagridviewcombobox column in datagrid (vb.net). I want to make that cell's combobox DropDownstyle to dropdown, when that particular cell gets the focus.
Posted
Updated 1-Sep-10 23:01pm
v2
Comments
Sandeep Mewara 2-Sep-10 13:15pm    
Whats the problem in changing the combobox style on focus event of cell?

1 solution

Hi,

Insert a datagridview in your form and name it "MyDataGridView".

To Add datagridviewcomboboxcolumns in your DataGridView, right click your datagridview in design window and select properties.

Then look for property "Columns". Then click the "..." button. Click Add button to add Columns...



Put the following code in your code window, to activate Combobox auto dropdown when focus ...



VB
Private Sub MyDataGridView_CellEnter(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles MyDataGridView.CellEnter
    ''# Code to Dropdown DataGridViewComboBox in single click
    ''Header Cell clicked -> ignore it.
    If (e.RowIndex = -1) Then
        Return
    End If


    MyDataGridView.BeginEdit(True)
    If TypeOf MyDataGridView.EditingControl Is DataGridViewComboBoxEditingControl Then
        Dim control As DataGridViewComboBoxEditingControl = MyDataGridView.EditingControl
        If Not IsNothing(control) Then
            control.DroppedDown = True
        End If
    End If
  '#End of Code to Dropdown DataGridViewComboBox 

End Sub





-----------
Regards,
B.LAKSHMI NARAYANAN
USE SOLUTIONS
TUTICORIN
+919940292099
www.usesolutions.net
usesolutions@yahoo.com
 
Share this answer
 

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