Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Fill datagridview combobox cell

Posted on 2012-03-31
5
Medium Priority
?
926 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 2000 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

[Webinar] Lessons on Recovering from Petya

Skyport is working hard to help customers recover from recent attacks, like the Petya worm. This work has brought to light some important lessons. New malware attacks like this can take down your entire environment. Learn from others mistakes on how to prevent Petya like worms.

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 …
1.0 - Introduction Converting Visual Basic 6.0 (VB6) to Visual Basic 2008+ (VB.NET). If ever there was a subject full of murkiness and bad decisions, it is this one!   The first problem seems to be that people considering this task of converting…
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…
Please read the paragraph below before following the instructions in the video — there are important caveats in the paragraph that I did not mention in the video. If your PaperPort 12 or PaperPort 14 is failing to start, or crashing, or hanging, …

618 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