Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Combo Box In DataGridView
Message
From
17/05/2009 22:37:11
 
General information
Forum:
ASP.NET
Category:
Coding, syntax and commands
Miscellaneous
Thread ID:
01398010
Message ID:
01400347
Views:
37
Hi Kevin,

You posted this question quite some time ago (I've been away from the UT for several weeks), so you may have already gotten an answer elsewhere, but if you haven't, I'll tell you what the problem is. You need to set the DisplayMember and ValueMember properties, just like you would any ComboBox control:
DataGridViewComboBoxColumn comboboxColumn = new DataGridViewComboBoxColumn();
comboboxColumn.DataSource = dsLocations;
comboboxColumn.DisplayMember = "Address";
comboboxColumn.ValueMember   = "LocationID";
~~Bonnie



>I think I posted something like this a while back but I cannot find it.
>
>I want to add a combo box to a DataGridView. So far I have:
>
>
>grdReceive.DataMember = dsInventory.Tables[0].TableName;
>grdReceive.DataSource = dsInventory;
>
>DataGridViewComboBoxColumn comboboxColumn = new DataGridViewComboBoxColumn();
>comboboxColumn.DataSource = dsLocations;
>comboboxColumn.HeaderText = "Location";
>comboboxColumn.Name = "Location";
>grdReceive.Columns.Add(comboboxColumn);
>grdReceive.Columns["Location"].DisplayIndex = 3;
>
>
>A couple of problems:
>
>1) I want to populate the combo from a different dataset than the DataGridView. I have a DS called dsLocations, and if I set , comboboxColumn.DataSource = dsLocations, the text "System.Data.DataGridView" appears in the combo. How do I correctly populate this combo from dsLocations?
>
>2) When I click on the combo, nothing happens. I have to click a second time to get the combo to open. It's almost as if I have to select the combo first. This doesn't seem right.
>
>Anyone?
Bonnie Berent DeWitt
NET/C# MVP since 2003

http://geek-goddess-bonnie.blogspot.com
Previous
Reply
Map
View

Click here to load this message in the networking platform