Click here to Skip to main content
13,000,982 members (70,720 online)
Rate this:
Please Sign up or sign in to vote.
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
private void InitializeComponent()
   this.UnitsTerms = new System.Windows.Forms.DataGridViewComboBoxColumn();

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
Updated 11-Feb-13 22:15pm

1 solution

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

Solution 1

Read this:[^]


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.
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)

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy | Mobile
Web02 | 2.8.170624.1 | Last Updated 12 Feb 2013
Copyright © CodeProject, 1999-2017
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