+ Reply to Thread
Results 1 to 8 of 8

Thread: Having a drop-down cell on datagrid

  1. #1
    J Trahair is offline VB.NET Forum Enthusiast J Trahair is on a distinguished programming path ahead
    .NET Framework
    .NET 3.0 (VS 2005/2008)
    Join Date
    May 2008
    Location
    Spain
    Posts
    92
    Reputation
    32

    Default Having a drop-down cell on datagrid

    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.

  2. #2
    InertiaM is offline VB.NET Forum Idol InertiaM puts e.f. hutton to shame InertiaM puts e.f. hutton to shame InertiaM puts e.f. hutton to shame InertiaM puts e.f. hutton to shame InertiaM puts e.f. hutton to shame InertiaM puts e.f. hutton to shame
    .NET Framework
    .NET 2.0
    Join Date
    Nov 2007
    Location
    Kent, UK
    Age
    40
    Posts
    569
    Reputation
    176

    Default

    Copied from a recent post by JohnH :-

    Code:
    Dim cell As New DataGridViewComboBoxCell
    cell.Items.Add("A")
    cell.Items.Add("B")
    Me.DataGridView1.Item(col, row) = cell
    Always parameterize your queries - read more here

    "When people discover the center of the universe, a lot of them will be disappointed to find they are not it."

  3. #3
    JohnH's Avatar
    JohnH is offline VB.NET Forum Moderator JohnH has a reputation beyond repute JohnH has a reputation beyond repute JohnH has a reputation beyond repute JohnH has a reputation beyond repute JohnH has a reputation beyond repute JohnH has a reputation beyond repute JohnH has a reputation beyond repute JohnH has a reputation beyond repute JohnH has a reputation beyond repute JohnH has a reputation beyond repute JohnH has a reputation beyond repute
    .NET Framework
    .NET 4.0
    Join Date
    Dec 2005
    Location
    Norway
    Age
    37
    Posts
    11,055
    Reputation
    1564

    Default

    Just add a Combobox column to the DataGridView when you configure its columns.

  4. #4
    InertiaM is offline VB.NET Forum Idol InertiaM puts e.f. hutton to shame InertiaM puts e.f. hutton to shame InertiaM puts e.f. hutton to shame InertiaM puts e.f. hutton to shame InertiaM puts e.f. hutton to shame InertiaM puts e.f. hutton to shame
    .NET Framework
    .NET 2.0
    Join Date
    Nov 2007
    Location
    Kent, UK
    Age
    40
    Posts
    569
    Reputation
    176

    Default

    Can we clarify - is this question about a single cell, or a whole column?
    Always parameterize your queries - read more here

    "When people discover the center of the universe, a lot of them will be disappointed to find they are not it."

  5. #5
    J Trahair is offline VB.NET Forum Enthusiast J Trahair is on a distinguished programming path ahead
    .NET Framework
    .NET 3.0 (VS 2005/2008)
    Join Date
    May 2008
    Location
    Spain
    Posts
    92
    Reputation
    32

    Default

    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.

  6. #6
    InertiaM is offline VB.NET Forum Idol InertiaM puts e.f. hutton to shame InertiaM puts e.f. hutton to shame InertiaM puts e.f. hutton to shame InertiaM puts e.f. hutton to shame InertiaM puts e.f. hutton to shame InertiaM puts e.f. hutton to shame
    .NET Framework
    .NET 2.0
    Join Date
    Nov 2007
    Location
    Kent, UK
    Age
    40
    Posts
    569
    Reputation
    176

    Default

    Sorry, my mistake then - I took "giving a cell a drop down combobox" at its literal meaning.
    Always parameterize your queries - read more here

    "When people discover the center of the universe, a lot of them will be disappointed to find they are not it."

  7. #7
    J Trahair is offline VB.NET Forum Enthusiast J Trahair is on a distinguished programming path ahead
    .NET Framework
    .NET 3.0 (VS 2005/2008)
    Join Date
    May 2008
    Location
    Spain
    Posts
    92
    Reputation
    32

    Default

    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 Code:
                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.

  8. #8
    JohnH's Avatar
    JohnH is offline VB.NET Forum Moderator JohnH has a reputation beyond repute JohnH has a reputation beyond repute JohnH has a reputation beyond repute JohnH has a reputation beyond repute JohnH has a reputation beyond repute JohnH has a reputation beyond repute JohnH has a reputation beyond repute JohnH has a reputation beyond repute JohnH has a reputation beyond repute JohnH has a reputation beyond repute JohnH has a reputation beyond repute
    .NET Framework
    .NET 4.0
    Join Date
    Dec 2005
    Location
    Norway
    Age
    37
    Posts
    11,055
    Reputation
    1564

    Default

    As I said, just add a combo column in Designer. You can also add the items there.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

     

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts