Solved

Fill datagridview combobox cell

Posted on 2012-03-31
5
887 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
  • 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

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Article by: Kraeven
Introduction Remote Share is a simple remote sharing tool, enabling you to see, add and remove remote or local shares. The application is written in VB.NET targeting the .NET framework 2.0. The source code and the compiled programs have been in…
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 seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.

747 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now