Solved

Fill datagridview combobox cell

Posted on 2012-03-31
5
910 Views
Last Modified: 2012-03-31
Hi,
I am using vb.net.

I need a code to fill the combobox cell in a datagridview.

Thanks in advance.
0
Comment
Question by:baabaa_nl
[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
  • 4
5 Comments
 
LVL 17

Expert Comment

by:nepaluz
ID: 37791327
You can either do this in the designer by setting the datasource or you can do this at load time, treating each cell inthe comboboxcolumn as an individual combobox and adding a datasource to it.

What is the data that you'd want bound and where are you getting it from? (i.e SQL, List etc)
0
 
LVL 17

Expert Comment

by:nepaluz
ID: 37791352
designer route
desgnYou can either add items manually through the designer (left screen) or assigne a datasource that is already existent in the project (right screen) via editing your datagridviewcomboboxcolumn properties (top screen)
0
 

Author Comment

by:baabaa_nl
ID: 37791356
i would like to add it programatically, and i would like to add a list of values manually from the code.
0
 
LVL 17

Accepted Solution

by:
nepaluz earned 500 total points
ID: 37791378
Assuming that the first column of your datagridview is a comboboxcolumn, you'd add this in your form load event
Dim DataList As New List(Of String) From {"First Item", "Second Item", "Third Item"}
For Each row As DataGridViewRow In Me.DataGridView1.Rows
    CType(row.Cells(0), DataGridViewComboBoxCell).DataSource = DataList
Next

Open in new window

0
 
LVL 17

Expert Comment

by:nepaluz
ID: 37791393
Or, you can have the datasource set in the RowsAdded event of the datagridview by
Dim DataList As New List(Of String) From {"First Item", "Second Item", "Third Item"}
Dim xSender = DirectCast(sender, DataGridView)
CType(xSender.Rows(e.RowIndex).Cells(0), DataGridViewComboBoxCell).DataSource = DataList

Open in new window

Again, the code above assumes that the comboboxcolumn is the first column
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

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

I think the Typed DataTable and Typed DataSet are very good options when working with data, but I don't like auto-generated code. First, I create an Abstract Class for my DataTables Common Code.  This class Inherits from DataTable. Also, it can …
Creating an analog clock UserControl seems fairly straight forward.  It is, after all, essentially just a circle with several lines in it!  Two common approaches for rendering an analog clock typically involve either manually calculating points with…
Come and listen to Percona CEO Peter Zaitsev discuss what’s new in Percona open source software, including Percona Server for MySQL (https://www.percona.com/software/mysql-database/percona-server) and MongoDB (https://www.percona.com/software/mongo-…
NetCrunch network monitor is a highly extensive platform for network monitoring and alert generation. In this video you'll see a live demo of NetCrunch with most notable features explained in a walk-through manner. You'll also get to know the philos…

688 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