Can I Have A DataGridView 'Combo-box'?

jsurpless

Well-known member
Joined
Jul 29, 2008
Messages
144
Programming Experience
Beginner
In MS Access, it's possible to have a pull-down menu for the user to select certain items for entry into a field...

Can I do that with a DataGridView?
 
If I am setting the contents of my DataGridView from an XML file as such

VB.NET:
MatchMakerXML_Dataset.ReadXml(c_MatchMakerXML.XMLFilePath)

ComponentTable_Matches_GridView.DataSource = MatchMakerXML_Dataset
ComponentTable_Matches_GridView.DataMember = "COMPONENT_MATCH"

How can I manipulate the individual columns?

The XML looks like this...

VB.NET:
<?xml version="1.0" standalone="yes"?>
<MATCHLIST>
  <COMPONENT_MATCH>
    <DATABASE />
    <AUTOCAD />
  </COMPONENT_MATCH>
</MATCHLIST>
 
You can add the columns in Designer first, and set the DataPropertyName to the data column name. One of the options is adding a column of type DataGridViewComboBoxColumn.
 
OK, I figured out how to refer to my various columns, even the auto-generated ones...

Before i start, I read on another site that there's a property that I can set to prevent columns from being auto-generated... would have expected that on the DataGridView but can't seem to find it?

What's the property I'd use on the column to change its type? The GUI seems to be 'ColumnType' but that property doesn't appear to exist?

ComponentTable_Matches_GridView.Columns("DATABASE").?
 
Dataset linking same as you previous post. Linking the combo column can be done the same way setting (Me.combocolumn.) DataSource/DisplayMember/ValueMember.

When you set DataPropertyName for the columns and bind a dataset no new columns are added for the mapped ones, non-mapped source columns are added, this can be turned off with DGVs AutoGenerateColumns property.
 
Can I use code to change the column type of a column?

Or do I have to set this in the GUI and then map data to a pre-built one?
 
You can always do the same in code and in Designer, what you do in Designer simply causes code to be generated.
VB.NET:
Dim col As New DataGridViewComboBoxColumn
etc...
 
Back
Top