Solved

Fill datagridview combobox cell

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

This article explains how to create and use a custom WaterMark textbox class.  The custom WaterMark textbox class allows you to set the WaterMark Background Color and WaterMark text at design time.   IMAGE OF WATERMARKS STEPS Create VB …
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…
With the power of JIRA, there's an unlimited number of ways you can customize it, use it and benefit from it. With that in mind, there's bound to be things that I wasn't able to cover in this course. With this summary we'll look at some places to go…
Learn how to create flexible layouts using relative units in CSS.  New relative units added in CSS3 include vw(viewports width), vh(viewports height), vmin(minimum of viewports height and width), and vmax (maximum of viewports height and width).

910 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

22 Experts available now in Live!

Get 1:1 Help Now