Solved

Populate Combobox in Datagridview Control

Posted on 2007-04-04
2
1,413 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Secure Your Active Directory - April 20, 2017

Active Directory plays a critical role in your company’s IT infrastructure and keeping it secure in today’s hacker-infested world is a must.
Microsoft published 300+ pages of guidance, but who has the time, money, and resources to implement? Register now to find an easier way.

Question has a verified solution.

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

If you're writing a .NET application to connect to an Access .mdb database and use pre-existing queries that require parameters, you've come to the right place! Let's say the pre-existing query(qryCust) in Access takes a Date as a parameter and l…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…
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 …

740 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