Solved

DataGridView with DataGridViewComboBoxColumn: How to single click for dropdown list?

Posted on 2006-06-27
2
1,938 Views
Last Modified: 2008-01-09
Hello,

I have  DGV on a form that is working perfectly well, except I want a single click on the cell to begin editing rather than clicking two times.  For example, I would like a single click on a DataGridViewComboBoxColumn's cell to cause the dropdown list to appear and a single click on a DataGridViewTextBoxColumn to permit the user to start editing the contents.  I have the written the following code, which is attached to the MouseUp event, but I am not certain what I should have it do to the cell to achieve my goals.  I've tried setting focus on mouse up, but to no avail.

Thanks in advance for the help!

Mike

        private void dataGridView_MouseUp(object sender, MouseEventArgs e)
        {
            DataGridView.HitTestInfo hti = dataGridView.HitTest(e.X, e.Y);

            try
            {
                if (hti.Type == DataGridViewHitTestType.Cell)
                {
                    //  What to do here????
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
            }
        }
0
Comment
Question by:mjgardne
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 5

Accepted Solution

by:
nickhoggard earned 50 total points
ID: 17008345
Hi,

I just wrote a solution for this at work today, but I dont have it here sorry.

The basic idea was to catch the DataGridView.EditControlShowing event, check the control (e.Control) and see if it can be cast to a ComboBox.  If it can then add an event handler for the GotFocus event and in that event handler call ComboBox.DroppedDown  = true

within the EditControlShowing event handler:
if gettype(combobox).IsAssignableFrom(e.Control.GetType) then
    removehandler ctype(e.Control, ComboBox).GotFocus, addressof _GotFocus
    addhandler ctype(e.Control, ComboBox).GotFocus, addressof _GotFocus
end if

private sub _GotFocus(sender as object, e as eventargs)
    ctype(e.control, combobox).DroppedDown = true
end sub

Hope this helps

Cheers

Nick

0
 

Author Comment

by:mjgardne
ID: 17013693
Here is the answer that I've discovered and it works perfectly!  No extra event handling code required to achieve the results that I required...

On form_load set:

dataGridView.EditMode = DataGridViewEditMode.EditOnEnter;
 
0

Featured Post

Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction This article series is supposed to shed some light on the use of IDisposable and objects that inherit from it. In essence, a more apt title for this article would be: using (IDisposable) {}. I’m just not sure how many people would ge…
Performance in games development is paramount: every microsecond counts to be able to do everything in less than 33ms (aiming at 16ms). C# foreach statement is one of the worst performance killers, and here I explain why.
Michael from AdRem Software explains how to view the most utilized and worst performing nodes in your network, by accessing the Top Charts view in NetCrunch network monitor (https://www.adremsoft.com/). Top Charts is a view in which you can set seve…
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…

687 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question