DataGridView... defaults to DataGridViewTextBoxColumn

  • Thread starter Thread starter johnb41
  • Start date Start date
J

johnb41

When you programmatically bind data to a DataGridView (VS2005), the
resulting columns are DataGridViewTextBoxColumns. Instead of that, i'd
like it to be a DataGridViewComboBoxColumn. How can I do this?

Thanks for the help!
John
 
Hi,

Here is a quick example.


Public Class Form1

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
Dim dt As New DataTable("Names")
dt.Columns.Add("Name")
dt.Columns.Add("State")
dt.LoadDataRow(New Object() {"Ken Tucker", "Florida"}, True)
dt.LoadDataRow(New Object() {"Cor Ligthert", "Netherlands"}, True)
dt.LoadDataRow(New Object() {"Terry Burns", "United Kingdom"}, True)
dt.LoadDataRow(New Object() {"Armin Zignler", "Germany"}, True)
dt.LoadDataRow(New Object() {"Herfried K. Wagner", "Austria"}, True)
dt.LoadDataRow(New Object() {"Jay B Harlow", "New York"}, True)
DataGridView1.DataSource = dt
DataGridView1.AllowUserToAddRows = False

DataGridView1.Columns.Remove("State")

Dim dgvCombo As New DataGridViewComboBoxColumn
With dgvCombo
.Width = 150
.Items.Add("Florida")
.Items.Add("Netherlands")
.Items.Add("United Kingdom")
.Items.Add("Germany")
.Items.Add("Austria")
.Items.Add("New York")
.DataPropertyName = "State"
.HeaderText = "State"
End With

DataGridView1.Columns.Add(dgvCombo)
End Sub

Ken
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top