Solved

Fill datagridview combobox cell

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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Introduction As chip makers focus on adding processor cores over increasing clock speed, developers need to utilize the features of modern CPUs.  One of the ways we can do this is by implementing parallel algorithms in our software.   One recent…
Parsing a CSV file is a task that we are confronted with regularly, and although there are a vast number of means to do this, as a newbie, the field can be confusing and the tools can seem complex. A simple solution to parsing a customized CSV fi…
Attackers love to prey on accounts that have privileges. Reducing privileged accounts and protecting privileged accounts therefore is paramount. Users, groups, and service accounts need to be protected to help protect the entire Active Directory …

738 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