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

Post New Web Links

Different ComboBox in Each Row of DataGridView

Posted By:      Posted Date: September 13, 2010    Points: 0   Category :Windows Application
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

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

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 can I fill a Combobox in a datagridview? C#


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?


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

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? 


Weird "string;#" in combobox


Ok, while I am digging and digging myself into the world that's called Sharepoint I come to the next challenge.


I have two lists Projects List and Project Issues. They both have an id field (which is not the ID field of the record) and a title. I created two calculated fields for both of the tables which combines the title and the number for displaying in other pages.



Projects List:

ProjectID: 2008-001

Project Name: First Project in 2008

Display Name (which is the calculated field): 2008-001 First Project in 2008


The calculated field formula is: =[ProjectID]&" "&[Project Name]

The field returns a string.


I also have a Worksheet list where my workers have to fill in their working hours. In this list I have two lookup fields. O

Combobox and Enter key


I have added a combobox to my page. Listview is updated based on selection from combobox. It is working great except it does not fire when Enter is pressed. User has to click on option from dropdown or has to press tab key to have Listview to populate. I want the user to be able type use arrow key to select option and then press the enter key for event to fire.

Using .net 3.5 and c#


ComboBox text/value selection?


When we select a value from combobox list, we can get it by combobox.selectedvalue.text, however when we enter a new value in combobox, we can get it by combobox.text when submitting a form.  During submission, how will we handle this situation? Either there is a single way of getting value in both situations or we'll have to tackle both situations separately?

Please help me tackling this situation. Thanks

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