Add Combobox column to datagridview using vb.net

Mike_Stevens
Mike_Stevens used Ask the Experts™
on
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

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Software Team Lead
Commented:
try add:

Dim chkbox As New DataGridViewCheckBoxColumn

  With chkbox
    .HeaderText = "Header"
    .Name = "chkName"
    .Width = 60
  End With
.Columns.Insert(2, chkbox)

Open in new window

Author

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

Thank you!

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial