Windows Develop Bookmark and Share   
 index > Windows Forms Data Controls and Databinding > DataGridView Error. Help !
 

DataGridView Error. Help !

I have a datagridview that is bound to a table. One of the columns is a comboboxcolumn. When I try to add a row to the grid I get the following error.

"the value of the datagridviewcomboboxcell is invalid"

Has anyone seen this yet?
MigrationUser 1  Thursday, December 16, 2004 6:06 PM
I have the same problem ! Did you find a solution ?
MigrationUser 1  Saturday, February 12, 2005 7:19 PM
You maybe have to add the default value of the combobox column in the "DefaultValuesNeeded" event.

I hope you'll solve this problem.
MigrationUser 1  Sunday, February 13, 2005 11:50 PM
Hi all, hope this helps.

Seems that when you add a row, the default value of the combobox cell needs to be identical to one of the items in the list.  I have handled this in my particular case by writing an event handler to give the cell a default value on creation.



    Private Sub grdEdit_DataError(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewDataErrorEventArgs) Handles grdEdit.DataError
        If sender.Equals(Me.grdEdit) Then
            If e.ColumnIndex = 1 Then
                Me.grdEdit.Rows(e.RowIndex).Cells(1).Value = Me.lstDta.Rows(0).Item(0)
            End If
        End If
    End Sub

lstDta = Data.Datatable object that populated the Items collection of the listbox.  I am assuming this method will also work for a databound control.
MigrationUser 1  Wednesday, April 20, 2005 3:13 PM
This is correct - you cannot have a value in a combobox cell be a value that doesn't exist in the combobox collection.

Hope this helps!
-mark
Program Manager
Microsoft
This post is provided "as-is"
MigrationUser 1  Monday, April 25, 2005 2:13 AM
This is not logical ! What if you simply want to have this field being "NULL" ? How can I have the first item in the ComboBox being "Blank", or "--Choose--", that will represent NULL in the DB ? My case is pretty common, I have a foreign key column that allow null values...
MigrationUser 1  Monday, May 02, 2005 11:27 AM
Null maps to not having anything selected in the combobox cell. To get null to map to "--choose--" then you'll need to add "--choose--" to the combobox or customize things a bit and instead of actually databinding the items in your combobox customize things: 

When a combobox cell becomes the CurrentCell,  I would build its Items collection based on the acceptable database values and include "--choose--" and set the cell's NullValue to "--choose--". You can do this in using the CurrentCellChanged event.

-mark
Program Manager
Microsoft
This post is provided "as-is"
MigrationUser 1  Wednesday, May 04, 2005 7:07 PM

You can use google to search for other answers

Custom Search

More Threads

• DataGridView & Style inheritance
• How to make currently selected row invisible ?
• how to get Row Value in DataGrid
• datagrid delete button
• how to solve AxOWC11 dll Error
• datagrid column value
• combining the eventHandlers for a RAD databound datagridView
• Listbox: Insert multiple values selected from listbox into database
• dynamic datagrid with differant colums and data for every query
• WF: Scheduler Calendar in C#