Solved

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

Posted on 2006-06-27
2
1,926 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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

This article introduced a TextBox that supports transparent background.   Introduction TextBox is the most widely used control component in GUI design. Most GUI controls do not support transparent background and more or less do not have the…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…
Attackers love to prey on accounts that have privileges. Reducing privileged accounts and protecting privileged accounts therefore is paramount. Users, groups, and service accounts need to be protected to help protect the entire Active Directory …

733 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