We help IT Professionals succeed at work.

Add Combobox column to datagridview using vb.net

216 Views
Last Modified: 2018-03-10
I have a winform that has a datagridview  and i am formatting the layout of the grid using using the following vb.net code.   I would like to have column 2 in the grid be a combobox column.   How can i change column from a textbox to a combobox using my existing code.

With Me.Datagridview1

             .AllowUserToAddRows = True
            .AllowUserToDeleteRows = True
            .AllowUserToOrderColumns = False
            .AllowUserToResizeColumns = False
            .AllowUserToResizeRows = False
            .AutoGenerateColumns = False

            .Columns(1).Width = 175
            .Columns(1).DataPropertyName = "Car_Color"
            .Columns(1).HeaderText = "Car Color"
            .Columns(1).HeaderCell.Style.Alignment = DataGridViewContentAlignment.MiddleCenter
            .Columns(1).DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleLeft

             .Columns(2).Width = 175
            .Columns(2.DataPropertyName = "Interior_Color"
            .Columns(2).HeaderText = "Interior Color"
            .Columns(2).HeaderCell.Style.Alignment = DataGridViewContentAlignment.MiddleCenter
            .Columns(2.DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleLeft

End With
Comment
Watch Question

CERTIFIED EXPERT
Commented:
This problem has been solved!
(Unlock this solution with a 7-day Free Trial)
UNLOCK SOLUTION

Author

Commented:
Thanks Ryan...thats exactly what i was looking for.

Thank you!