Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

ComboBox - Disabling Selected Text Logic

Posted on 2010-11-26
3
Medium Priority
?
437 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 500 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 500 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

Technology Partners: 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

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…
It’s quite interesting for me as I worked with Excel using vb.net for some time. Here are some topics which I know want to share with others whom this might help. First of all if you are working with Excel then you need to Download the Following …
this video summaries big data hadoop online training demo (http://onlineitguru.com/big-data-hadoop-online-training-placement.html) , and covers basics in big data hadoop .
Screencast - Getting to Know the Pipeline

824 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