Windows Develop Bookmark and Share   
 index > Windows Forms Data Controls and Databinding > DataGridViewComboBoxCell - CellValidating event not working
 

DataGridViewComboBoxCell - CellValidating event not working

I am using Answereda DataGridViewComboBoxColumn column in a datagridview control that is the detail records of amaster/detail form. One of the DataGridViewComboBoxColumncolumns in the detail datagridview is bound to a SQL Server datasource to get the list. When adding a new record to the detail datagridview, when I enter the cell with the combo box it immediately displays in the cell the first item in the list. However, it seems that this first item is actually not selected for entry into the cell and is not actually entered into the cell. I cannot figure out how to correctly test for this conditionand notify the user that they have to make a selection from the list. Because the first list item is already displayed in the cell, it appears that the selection has been made. However, you have to click on the cell again to get the drop down list to appear and then select an item from the list. If I don't select a list item and move to a new cell the comboBoxCell value becomes NULL.

What is weird is that in the CellValidating event the property e.FormattedValue is the set tothe first item in the list. Also, the

dataGridView.CurrentCell.EditedFormattedValue is set to the first item in the list and dataGridView.CurrentCell.FormattedValue is empty. Initially I checked dataGridView.CurrentCell.FormattedValue but I have found this is always empty even after an item is picked from the list. I think the CellValidating event to check this condition since it includes an e.Cancel property. Has anyone else had this problem and have a fix I could use. Thanks in advance.

Dennis Geasan

DG3  Wednesday, July 22, 2009 12:32 AM

Hi Dennis,

This reason why the valueof the first item in the combobox drop down list is not committed to the cell is that the user doesn't make the selection action in the drop down list, so the SelectedValueChanged event of the hosted combobox is not raised. In this case, nothing will be committed back to the cell. Asyou can see, this behavior is by design.

A solution is to set a default value for the correspondingdata column in the DataTable. You can do it in the DataSet designer or in code.

Hope this helps.
If you have any question, please feel free to let me know.

Sincerely,
Linda Liu


Please remember to mark the replies as answers if they help and unmark them if they provide no help. end us any feedback you have about the help from MSFT at fbmsdn@microsoft.com.
Linda Liu  Wednesday, July 22, 2009 7:25 AM

Hi Dennis,

This reason why the valueof the first item in the combobox drop down list is not committed to the cell is that the user doesn't make the selection action in the drop down list, so the SelectedValueChanged event of the hosted combobox is not raised. In this case, nothing will be committed back to the cell. Asyou can see, this behavior is by design.

A solution is to set a default value for the correspondingdata column in the DataTable. You can do it in the DataSet designer or in code.

Hope this helps.
If you have any question, please feel free to let me know.

Sincerely,
Linda Liu


Please remember to mark the replies as answers if they help and unmark them if they provide no help. end us any feedback you have about the help from MSFT at fbmsdn@microsoft.com.
Linda Liu  Wednesday, July 22, 2009 7:25 AM

You can use google to search for other answers

Custom Search

More Threads

• have a problem while AutoResize the DataGridView Columns and Rows on Beta 2
• Datagridview column wrapping?
• Format Double to display negatives in parenthesis
• Refreshing databound ComboBox error
• No Columns from Stored Procedure
• many-to-one relationships
• How Can I Make a DataGridView Row/Cell Selected?
• GridView, BusinessObject binding and Null
• DataGrid new row event
• No CellValueNeeded event in Virtual mode