Click to See Complete Forum and Search --> : DataGridView Combo box


shers
April 8th, 2009, 02:11 AM
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

Cimperiali
April 8th, 2009, 05:37 AM
a small trick you could work on...

(vs2008 and framework 3.5, but it should work on 2.0 too)

shers
April 8th, 2009, 07:45 AM
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.

Cimperiali
April 8th, 2009, 03:43 PM
sorry, I am going on holidays...Value is there...look at combo selectedValue...

shers
April 8th, 2009, 11:58 PM
I didn't find selected value.

Anyways, enjoy your holidays!

dglienna
April 9th, 2009, 12:39 AM
What if you double-click on that column? That should give you a CLICK event or CHANGE event.

Cimperiali
April 20th, 2009, 10:36 AM
here: add this code to the example, then launch it, then change a valuye in the combo and move to another column or row:

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