Solved

Populate Combobox in Datagridview Control

Posted on 2007-04-04
2
1,410 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

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
VB.NET - Error - Object not set in Module 4 39
Modal Popup Extender control 1 37
No Data for DropDown List 2 28
Complex SQL statement in VB.NET 7 31
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 …
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

840 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