Solved

Populate Combobox in Datagridview Control

Posted on 2007-04-04
2
1,408 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
ID: 18851884
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
ID: 18852114
Thanks LearnedOne.  Exactly what I was looking for.

RichW
0

Featured Post

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
SQL LINE CONTINUATION ISSUE 12 33
get column names from table in vb.net 8 28
Write to a printer using vb.net 9 26
Obtain cell value using column ID in DataGrid using VB.NET 2 18
Article by: jpaulino
XML Literals are a great way to handle XML files and the community doesn’t use it as much as it should.  An XML Literal is like a String (http://msdn.microsoft.com/en-us/library/system.string.aspx) Literal, only instead of starting and ending with w…
Microsoft Reports are based on a report definition, which is an XML file that describes data and layout for the report, with a different extension. You can create a client-side report definition language (*.rdlc) file with Visual Studio, and build g…
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

773 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