.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Win Surprise Gifts!!!

Top 5 Contributors of the Month
Post New Web Links

How can I fill a Combobox in a datagridview? C#

Posted By:      Posted Date: October 21, 2010    Points: 0   Category :Windows Application

I have made by code a datagridview. This datagridview has several comboboxes.

I want to populate this comboboxes at runtime. But I don't know how.

The code I tried:

NaardataGridView2.CurrentCell.Value = getKolommen(selVanTabellen);


getKolommen give a datatable with names. The above code doesn't work. I want something like:

NaardataGridView2.CurrentCell.DataSource = getKolommen(selVanTabellen);


Can some one help me?


View Complete Post

More Related Resource Links

Combobox in DataGridView

Hi, How do I setup a selected value for a combobox column in datagridview? Unlike a regular combobox I can't use: SelectedValue = 1; I'll give an example :Let's say I have a datagrid which is consisted of two datasets tables: one table which contains 300 entries for different types of cars, and a combobox column which contains a list of 10 car makers (that's the second table). The car maker's code is the primary key in the combobox column's value member and the foreign key in the first table. How do I load the datagrid so that t the combobox will display the correct car maker for every car entry (300 in total)? here's my current code: private void SetupDataGridView() { this.Controls.Add(carsGrid); DataGridViewComboBoxColumn comboGrid = new DataGridViewComboBoxColumn(); carsGrid.DataSource = dsCars.Tables[1]; carsGrid.DisplayMember = "CarMakerName"; carsGrid.ValueMember = "CarMakerID"; carsGrid.DataSource = dsCars.Tables[0]; carsGrid.Columns.Add(comboGrid); } Thanks, Udi

Different ComboBox in Each Row of DataGridView

Hi,   Can I have a ComboBoxColumn in a DataGridView with different items in the ComboBox of each row?   For instance, suppose there's a DataGridView in a Windows Form with rows of customer info. There's a column that shows the gender and a ComboBoxColumn to set the title. If the customer is male, the ComboBox will contain "Mr", "Dr" etc, otherwise it will have "Miss", "Mrs" etc.   How can this be done?   I saw this post but can't quite understand what it means. http://forums.microsoft.com/msdn/ShowPost.aspx?PostID=3311173&SiteID=1     Thanks, ywb

problem in make editable a combobox in datagridview in c#

how do i make my datagridview combobox aditable for the user while i has a drop down list. in this case sometimes user needs to edit the selected item from the list.how can i implement this?

DataGridView ComboBox visual style differs for same app on different systems



In a windows forms application developed with VB2008 Express the DataGridView ComboBox is rendered differently on different systems. 


On Windows XP Pro SP3, where the app was developed, the combo box appears as follows:

Well, apparently images can't be pasted to these threads so I'll have to try to describe the appearance.

Appearance in Windows XP:

Rectangular box with the same shape, color and appearance as a DataGridView TextBox except that it has a square drop-down button at it's right edge the same color as a ToolStrip or ScrollBar buttons/elevator.

Appearance in Windows 7:

Rounded rectangular gray box, lighter on the top half to make it appear bowed out along it's horizontal axis with a rectangular drop-down button, also gray.  This appearance is displeasing alongside the flat, rectangular, white background text and image boxes in the same DataGridView.

Additional information:

Salient DataGridView properties:
AutoSizeColumnsMode: None
AutoSizeRowsMode: None
BorderStyle: FixedSingle
CellBorderStyle: Single

Datagridview combobox.DroppedDown issues that require (2) clicks and not (1)


I have been reviewing following link regarding datagridview.combobox.droppeddown...the last entry is apparently not VB.NET.  Else I am missing something.


The last entry supposedly will work, however I can't come close.

Also, to expand on the issue I have is that I am attempting to click on a combobox cell at any time...whether it's the currently selected row or a different row in the gridview.  If it is a different row, that is really where I experience the problem.  I've attempted to use the following:


Private Sub dataGridView1_EditingControlShowing(ByVal sender As Object, _


ByVal e As DataGridViewEditingControlShowingEventArgs) _


How to fill different ComboBoxes in a DataGridView control with C#?

I have a datagridview with 3 comboboxes.
When in combobox 1 (=Rownumber = 1) AA is selected then at runtime combobox2 has to be filed with some value. 
This value is comming from a DataTable.
When some value is selected in combobox2 (Also RowNumber = 1), then at runtime combobox3 (also RowNumber = 1) has to be filled with some value also comming from a DataTable.

Above means that when combobox1 where the columnindex is 0 has the value:

When AA is selected ComboBox2 where the columnindex is 0 must have the value (ComboBox2 is must be filled at runtime and the values are comming from a DataTable):

When 11 is selected ComboBox3 where the columnindex is 0 must have the value (ComboBox3 is must be filled at runtime and the values are comming from a DataTable):


At RowNumber 2 ComboBox1 has the value:

when BB is selected, ComboBox2 also at RowNumber 2 must have the value (ComboBox2 is must be filled at runtime and the values are comming from a DataTable):

Datagridview combobox


I have a bound datagridview with a combobox that is populated from another datasource.  I am trying to bind a label to the same datasource that is used in the combobox.  When the combobox selection is  changed I need the label to change with the corresponing row in the datasource.

Here is the code:



Me.CostItemsTableAdapter.FillByProjectId(Me.BuildersJobCostDatabaseDataSet.CostItems, publicCurrentProjectId)

combobox in a datagridview error


I used t his link for comboboxin a winforms datagridview.



In the designer, click on the arrow (gridview tasks) on the gridview.
I set the datasource of the grid to the appropriate dataset.
Then, click on edit columns. On this, changed one one column Type to datagridviewcomboboxcolumn.

DataPropertyName= "Vehicle"
DataSource = "VehicleDataset" - This is a different dataset which has 2 columns (ID and Name)
DisplayMember = "VehicleName"
ValueMember = "VehicleID"

This combox get teh data from a table called vehicles which has id and name. i populate them in vehicledataset.

When i load the form, i am getting a error.
I trapped the error in a datagridview_dataerror event
e.message  - Argument exception - datagrieviewcomboboxcell value is not valid.

Why i am gettign this error if i am using the value member?


Custom Editing Behavior for DataGridView TextBox Columns

For various reasons I'm using a DataGridView instead of a ListView, and while configuring the DataGridView to look like a ListView wasn't much of a problem, there's one thing that got on my nerves, which is the behavior of textbox cells in edit mode: It is much too easy to leave the edit mode accidentally, simply by pressing the cursor keys at the wrong time. For example when the text caret is positioned behind the last character of the textbox cell content, and you press the right arrow key

AutoCompleteStringCollection for text box in DataGridView 2.0

I have been searching for a way to have autocomplete in a DataGridTextBox
object. There does not appear to be an obvious way to do this like you would
for a TextBox outside of a grid using the AutoCompleteCustomSource. Any
thoughts on how I can add this collection? :)

How to display related tables in one crystal report and how to link this report with combobox?


Hi! I want to display a crystal report in my vb.net application. Suppose I have tables named student details, student marks, student address, etc... Now if I want to display all these details (fields of all tables) in one crystal report (with page breaks if necessary) then how will I achieve it. I will be providing a combo box in my application that contains list of student names. How can I link this combo box with the cystal report to dynamically display report for different student on selected index change of combo box? Help me friends. An example would be appreciable.

C++ at Work: Addin a Combobox Cancel Feature


This month Paul DiLascia codes some Microsoft Office-style dialog box features.

Paul DiLascia

MSDN Magazine August 2006

Dev Q&A: DataGridView


After receiving a late-breaking news bulletin at magazine headquarters early this month stating that the Web is just a fad that will never amount to anything, we have reluctantly decided to retire our venerable Web Q&A column and replace it with one we like to call Dev Q&A.

Edited by Nancy Michell

MSDN Magazine January 2006

ActiveX and Visual Basic: Enhance the Display of Long Text Strings in a Combobox or Listbox


The combobox and listbox controls in Visual Basic have no built-in support for displaying text strings that are too long to fit in the visible area of either control. This article describes several techniques to improve the readability of long strings in each control. The first technique uses tooltips to display a combobox or listbox item. The other techniques, which use various Windows APIs, include adding a horizontal scrollbar for a listbox and determining the necessary width of the longest string given the font attributes of the text. The required steps are described for both comboboxes and listboxes.

John Calvert

MSDN Magazine December 2000

How to fill out a form as another user , while using profiles database


I have created an InfoPath 2007 form. It works great.. I have 5 data connections to sharepoint lists and profile's database. The form displays public data (profile database) about the user, such as name, manager.. etc.

What I would like to do is have an option on the form that says " If you are not this person , click here" , manually type the persons last name , and bring up their information.

Basically , there are some people who will have someone else fill the form out for them. But I don't want them to be giving out their username and password to the system.

I want the ability to fill out a form as another user without logging off sharepoint. 

Binding value to combobox or dropdown


How can we bind a value to a combobox or dropdown? What is the property for binding a value? 


Library - Fill Columns with data from email

I have an inbound email enabled Library.  The Library has several columns created for it.  I would like to be able to send an email into the Library and have these columns filled from information in the email.  Is this possible using WSS 3.0?  What are the basic steps?  If I understand SharePoint well enough, I'm guessing is that I have to include the columns as Metadata in the body of the email and then assign this Metadata to the appropriate Library columns when new email is uploaded to the Library.
ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  Silverlight  Others  All   

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend