DataGridView ComboBox Column does not display value if not in the .Items.Add

J Trahair

Well-known member
Joined
May 14, 2008
Messages
175
Location
Spain
Programming Experience
10+
DataGridView ComboBox Column does not display value if not in the .Items.Add., and may display the wrong value.

I use VB 2005 Professional. I have a database with some values in a table row.

I can successfully get those to display in the DGV. Eg., from the database the combobox displays these names in the drop down box:
Albert
Bill
Charlie
Dave

I can click on any of these and save to another table in the database, eg. a list of tasks done by each man, then I can redisplay it and they are all there.

If (say) Bill is deleted from the source table, of course Bill is no longer in the drop down box. However, when displaying the data from the Task table, then Bill's name is replaced by another name at display time. In the Tasks table Bill's name is still current.

How can I get the DGV to display a value not in the drop down list?

Also, it seems I have to click twice to get the drop down box to drop - once to get focus, another click to drop the list of values.

Thank you.
 
Here's the code I use:
VB.NET:
            Dim NewColumn As New DataGridViewComboBoxColumn() 'Declare new DGV CC
            With NewColumn 'Set Properties
                .DataPropertyName = "TerminalLocations" 'Name
                .HeaderText = "User location" 'Heading
                .DropDownWidth = 160 'Width Of DropDown Box
                .Width = 294 'Display Width
                .MaxDropDownItems = 10
                .FlatStyle = FlatStyle.Standard
                gstrCollectionOfTerminalLocationsTemp = gstrCollectionOfTerminalLocations
                'Fill the combobox with values from the table:
                Do Until gstrCollectionOfTerminalLocationsTemp = ""
                    .Items.Add(Mid$(gstrCollectionOfTerminalLocationsTemp, 1, InStr(gstrCollectionOfTerminalLocationsTemp, "^") - 1))
                    gstrCollectionOfTerminalLocationsTemp = Mid$(gstrCollectionOfTerminalLocationsTemp, InStr(gstrCollectionOfTerminalLocationsTemp, "^") + 1)
                Loop
            End With
            grd1.Columns.Add(NewColumn) 'Add The Column
 
Back
Top