ComboBox programmatically take focus away

Posted on 2011-10-17
Medium Priority
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
  • 2

Expert Comment

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

Accepted Solution

raysonlee earned 2000 total points
ID: 36978040
       If DataGridView1.CurrentCell IsNot Nothing Then
            Dim rowIndex As Integer = DataGridView1.CurrentCell.RowIndex
            DataGridView1.CurrentCell = Nothing
            DataGridView1.Rows(rowIndex).Selected = True
        End If

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
This lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …
Loops Section Overview
Suggested Courses

839 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