ComboBox programmatically take focus away

Posted on 2011-10-17
Last Modified: 2012-06-27

I am using WIndows Forms. I have a ComboBox control on my form. I want programmatically take away focus from my ComboBox, so it is no longer selected.

In fact, I am using a DataGridView with custom column - when in edit mode, ComboBox appears. My real problem is that when I select row header, edited ComboBox remains selected, but I need to select row and un-select every cell in that row. And idea how to get focus away from ComboBox?

Please note: my custom column is not of type DataGridViewComboBoxColumn - it's completely customized and when in edit mode, ComboBox appears in the cell.

Greetings, Frenky
Question by:AntonioRodrigo
    LVL 9

    Expert Comment

    I suppose dgv.endedit() will end the edit mode but not losing focus. How about dgv.currentcell = nothing or set it to another cell?
    LVL 9

    Accepted Solution

           If DataGridView1.CurrentCell IsNot Nothing Then
                Dim rowIndex As Integer = DataGridView1.CurrentCell.RowIndex
                DataGridView1.CurrentCell = Nothing
                DataGridView1.Rows(rowIndex).Selected = True
            End If

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    How your wiki can always stay up-to-date

    Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
    - Increase transparency
    - Onboard new hires faster
    - Access from mobile/offline

    Suggested Solutions

    Title # Comments Views Activity
    Email Body 4 30
    vb linq Count Distinct? 1 29
    How to trouble shoot .net contact form 3 17
    Any reason why this might be bad? 7 27
    Creating an analog clock UserControl seems fairly straight forward.  It is, after all, essentially just a circle with several lines in it!  Two common approaches for rendering an analog clock typically involve either manually calculating points with…
    Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
    Need more eyes on your posted question? Go ahead and follow the quick steps in this video to learn how to Request Attention to your question. *Log into your Experts Exchange account *Find the question you want to Request Attention for *Go to the e…
    Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

    779 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

    Need Help in Real-Time?

    Connect with top rated Experts

    15 Experts available now in Live!

    Get 1:1 Help Now