Click here to Skip to main content
15,896,557 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi, I am new to C# and I have a problem that I can find vaguely similar postings for but nothing that quite solves my problem:

I have a form with a user control which contians a DataGridView, which contains a DataGridViewComboBoxColumn, which contains DataGridViewComboBoxCells.
The automatically generated method is
C#
private void InitializeComponent()
{
   this.UnitsTerms = new System.Windows.Forms.DataGridViewComboBoxColumn();
   etc...   
}


When I run my application, the first time I click on the combo box cell, the click is ignored. the next time I click it the combo box is activated and it allows me to select from the drop down list. If I add an event andler for the cell, then this is entered on the first click, but I still have to do a second click to change the combo box value.
Posted
Updated 11-Feb-13 22:15pm
v2

1 solution

Read this: http://msdn.microsoft.com/en-us/library/system.windows.forms.datagridview.cellcontentclick%28v=vs.85%29.aspx[^]

Remarks:


This event occurs when the cell content is clicked. It also occurs when the user presses and releases the SPACEBAR while a button cell or check box cell has focus, and will occur twice for these cell types if the cell content is clicked while pressing the SPACEBAR.

Use this event to detect button clicks for a DataGridViewButtonCell or link clicks for a DataGridViewLinkCell.

For clicks in a DataGridViewCheckBoxCell, this event occurs before the check box changes value, so if you do not want to calculate the expected value based on the current value, you will typically handle the DataGridView.CellValueChanged event instead. Because that event occurs only when the user-specified value is committed, which typically occurs when focus leaves the cell, you must also handle the DataGridView.CurrentCellDirtyStateChanged event. In that handler, if the current cell is a check box cell, call the DataGridView.CommitEdit method and pass in the Commit value.

For more information about handling events, see Consuming Events.


Probably, you need to use another event.
 
Share this answer
 
Comments
Jackie Lloyd 12-Feb-13 4:17am    
Many thanks for this - I see what you mean. However I just noticed that my original description was not accurate, so I have updated my question. I understand what is happening a bit more now but still don't know why. So even if I have no event handler, the combo box needs two clicks to be abe to select one of its items - why is this?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900