Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
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
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 11-Feb-13 7:12am
Edited 11-Feb-13 22:15pm
v2

1 solution

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

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.
  Permalink  
Comments
Jackie Lloyd at 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)

  Print Answers RSS
0 OriginalGriff 339
1 DineshMaind 95
2 Sergey Alexandrovich Kryukov 94
3 majid torfi 85
4 kbrandwijk 75
0 Zubair MCA 55
1 OriginalGriff 55
2 sankarsan parida 55
3 harshavardhan12345678 45
4 Sandeep Londhe 45


Advertise | Privacy | Mobile
Web04 | 2.8.140827.1 | Last Updated 12 Feb 2013
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100