Solved

ComboBox - Disabling Selected Text Logic

Posted on 2010-11-26
3
429 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
3 Comments
 
LVL 83

Accepted Solution

by:
CodeCruiser earned 125 total points
Comment Utility
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
Comment Utility
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
Comment Utility
Excellent.  Thx.  Both solutions would work but from different philosophical perspectives.  

CodeCruisers idea is faster to implement...
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Since .Net 2.0, Visual Basic has made it easy to create a splash screen and set it via the "Splash Screen" drop down in the Project Properties.  A splash screen set in this manner is automatically created, displayed and closed by the framework itsel…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…

772 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

10 Experts available now in Live!

Get 1:1 Help Now