Solved

Populate Combobox in Datagridview Control

Posted on 2007-04-04
2
1,398 Views
Last Modified: 2010-08-05
VB 2005

I am trying to populate a combobox in a Datagridview control with data from an arraylist.  I can't figure out how to bind the arraylist to the combobox.

The combobox is in the first cell of the Datagridview.

Does anyone know how to do this?

Thanks

RichW
0
Comment
Question by:RichW
2 Comments
 
LVL 96

Accepted Solution

by:
Bob Learned earned 250 total points
Comment Utility
You could do something like this:

Dim comboboxColumn As New DataGridViewComboBoxColumn()
comboboxColumn.DataPropertyName = "ptitle"
comboboxColumn.HeaderText = "Title"
comboboxColumn.DropDownWidth = 50
comboboxColumn.Width = 50
comboboxColumn.MaxDropDownItems = 5
comboboxColumn.FlatStyle = FlatStyle.Flat

Dim dbComboCommand As New OleDbCommand()
dbComboCommand.Connection = dbConn
dbComboCommand.CommandText = "SELECT title FROM Titles"
Dim dbComboDA As New OleDbDataAdapter(dbComboCommand)
Dim Cds As New DataSet()
dbComboDA.Fill(Cds, "results")

comboboxColumn.DataSource = Cds.Tables[0]
comboboxColumn.ValueMember = "title"
comboboxColumn.DisplayMember = comboboxColumn.ValueMember

dataGridView1.Columns.Insert(1, comboboxColumn)

Bob
0
 
LVL 4

Author Comment

by:RichW
Comment Utility
Thanks LearnedOne.  Exactly what I was looking for.

RichW
0

Featured Post

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

Well, all of us have seen the multiple EXCEL.EXE's in task manager that won't die even if you call the .close, .dispose methods. Try this method to kill any excels in memory. You can copy the kill function to create a check function and replace the …
Article by: Kraeven
Introduction Remote Share is a simple remote sharing tool, enabling you to see, add and remove remote or local shares. The application is written in VB.NET targeting the .NET framework 2.0. The source code and the compiled programs have been in…
This video discusses moving either the default database or any database to a new volume.
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

772 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now