CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 7 of 7
  1. #1
    Join Date
    Apr 2004
    Posts
    265

    DataGridView Combo box

    Hi,

    I have a DataGridView on a form that is being populated from a SQL table dataset by giving criteria from a previous form. I have 6 columns in the dataset, of which the last column should be combo box column containing items "Done" and "Pending". How do I make this bound column to a combo box column and display the value as well as the alternate item too in the combo box?

    Thanks

  2. #2
    Join Date
    Jul 2000
    Location
    Milano, Italy
    Posts
    7,726

    Re: DataGridView Combo box

    a small trick you could work on...

    (vs2008 and framework 3.5, but it should work on 2.0 too)
    Attached Files Attached Files
    ...at present time, using mainly Net 4.0, Vs 2010



    Special thanks to Lothar "the Great" Haensler, Chris Eastwood , dr_Michael, ClearCode, Iouri and
    all the other wonderful people who made and make Codeguru a great place.
    Come back soon, you Gurus.

  3. #3
    Join Date
    Apr 2004
    Posts
    265

    Re: DataGridView Combo box

    WOW! It worked!

    I had been struggling with this since yesterday.

    You are great, man!

    I would like to get your help on one more issue. I have an Image Column in the same datagridview, wherein, it displays one image when the displayed item in the combobox is "Pending" and another image when the displayed item in the combobox is "Done". I can't figure out how to go about it. I tried this

    If grdRow.Cells("cb").Value = "Pending" Then

    But it doesn't display any value.

  4. #4
    Join Date
    Jul 2000
    Location
    Milano, Italy
    Posts
    7,726

    Re: DataGridView Combo box

    sorry, I am going on holidays...Value is there...look at combo selectedValue...
    ...at present time, using mainly Net 4.0, Vs 2010



    Special thanks to Lothar "the Great" Haensler, Chris Eastwood , dr_Michael, ClearCode, Iouri and
    all the other wonderful people who made and make Codeguru a great place.
    Come back soon, you Gurus.

  5. #5
    Join Date
    Apr 2004
    Posts
    265

    Re: DataGridView Combo box

    I didn't find selected value.

    Anyways, enjoy your holidays!

  6. #6
    Join Date
    Jan 2006
    Location
    Fox Lake, IL
    Posts
    15,007

    Re: DataGridView Combo box

    What if you double-click on that column? That should give you a CLICK event or CHANGE event.
    David

    CodeGuru Article: Bound Controls are Evil-VB6
    2013 Samples: MS CODE Samples

    CodeGuru Reviewer
    2006 Dell CSP
    2006, 2007 & 2008 MVP Visual Basic
    If your question has been answered satisfactorily, and it has been helpful, then, please, Rate this Post!

  7. #7
    Join Date
    Jul 2000
    Location
    Milano, Italy
    Posts
    7,726

    Re: DataGridView Combo box

    here: add this code to the example, then launch it, then change a valuye in the combo and move to another column or row:
    Code:
     Private Sub grdExample_CellEndEdit(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles grdExample.CellEndEdit
            If e.ColumnIndex = grdExample.ColumnCount - 1 Then
                MessageBox.Show("Here: value is " & grdExample.Rows(e.RowIndex).Cells(e.ColumnIndex).Value)
            End If
        End Sub
    ...at present time, using mainly Net 4.0, Vs 2010



    Special thanks to Lothar "the Great" Haensler, Chris Eastwood , dr_Michael, ClearCode, Iouri and
    all the other wonderful people who made and make Codeguru a great place.
    Come back soon, you Gurus.

Posting Permissions

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





Click Here to Expand Forum to Full Width

Featured