Solved

ComboBox - Disabling Selected Text Logic

Posted on 2010-11-26
3
434 Views
Last Modified: 2012-08-14
Hi,

I have a combobox control with the DropDownStyle set to DropDownList.  Whenever I change the combobox by selecting a new item from the dropdown list, the entire width of the text area of the combobox changes to the selected state (dark blue with white text)

In my combobox_SelectedIndexChanged event, the last thing I try to do is:
cmb.Select(0,0)

But this does not seem to undo the selected color from the control.

How do I turnoff / disable / step around this selected text issue.
0
Comment
[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
3 Comments
 
LVL 83

Accepted Solution

by:
CodeCruiser earned 125 total points
ID: 34219514
Try setting focus to some other control such as this

txtName.Focus

This will remove focus from combobox and the blue color.
0
 
LVL 32

Assisted Solution

by:Erick37
Erick37 earned 125 total points
ID: 34219677
You could "Owner Draw" the combobox to achieve this.

Set the DrawMode to OwnerDrawFixed and handle the Drawitem event to get rid of the selection rectangle:
Private Sub ComboBox1_DrawItem(ByVal sender As Object, ByVal e As System.Windows.Forms.DrawItemEventArgs) Handles ComboBox1.DrawItem

		e.Graphics.FillRectangle(Brushes.White, e.Bounds)

		If e.Index > -1 Then
			e.Graphics.DrawString(ComboBox1.Items(e.Index).ToString, e.Font, New SolidBrush(e.ForeColor), New RectangleF(e.Bounds.X, e.Bounds.Y, e.Bounds.Width, e.Bounds.Height))
		End If

		If (e.State And DrawItemState.Selected) <> 0 Then
			ControlPaint.DrawFocusRectangle(e.Graphics, e.Bounds)
		End If

	End Sub

Open in new window

0
 

Author Closing Comment

by:RobertFromSecretWeapons
ID: 34219760
Excellent.  Thx.  Both solutions would work but from different philosophical perspectives.  

CodeCruisers idea is faster to implement...
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

1.0 - Introduction Converting Visual Basic 6.0 (VB6) to Visual Basic 2008+ (VB.NET). If ever there was a subject full of murkiness and bad decisions, it is this one!   The first problem seems to be that people considering this task of converting…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
In this video, viewers are given an introduction to using the Windows 10 Snipping Tool, how to quickly locate it when it's needed and also how make it always available with a single click of a mouse button, by pinning it to the Desktop Task Bar. Int…
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…

630 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