Having a drop-down cell on datagrid

J Trahair

Well-known member
Joined
May 14, 2008
Messages
175
Location
Spain
Programming Experience
10+
Is there a way of giving a cell a drop down combobox with a small number of choices in it, eg. choosing a currency symbol? In VB6 there was BuildCombo etc.

Thank you.
 
Copied from a recent post by JohnH :-

VB.NET:
Dim cell As New DataGridViewComboBoxCell
cell.Items.Add("A")
cell.Items.Add("B")
Me.DataGridView1.Item(col, row) = cell
 
Just add a Combobox column to the DataGridView when you configure its columns.
 
Can we clarify - is this question about a single cell, or a whole column?
 
This will be for all cells in a given column, except where there is no value in column 2 in that row (for example).
Eg. column 8 has the ComboBox if column 2 is valid.
 
Sorry, my mistake then - I took "giving a cell a drop down combobox" at its literal meaning.
 
Sorry, I should have explained it better to begin with.

I have a datagrid in VB 2005, where each cell in column 8 is a combobox contain currency symbols eg. £, €, $. When the user enters any cell in this column, they are forced to accept one of the currency symbols, and not to type in something else.

I tried
HTML:
            Dim cell As New DataGridViewComboBoxCell
            cell.Items.Add("A")
            cell.Items.Add("B")
            Me.grd1.Item(grd1.CurrentCellAddress.X, grd1.CurrentCellAddress.Y) = cell
in grd1_CellEnter, but the behaviour was quirky and there were error messages. Plainly, that's the wrong place, although the code segment looks promising.

Where should I put the code, for best results? Thank you.
 
As I said, just add a combo column in Designer. You can also add the items there.
 
Back
Top