Solved

ComboBox - Disabling Selected Text Logic

Posted on 2010-11-26
3
433 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

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

This article explains how to create and use a custom WaterMark textbox class.  The custom WaterMark textbox class allows you to set the WaterMark Background Color and WaterMark text at design time.   IMAGE OF WATERMARKS STEPS Create VB …
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.
Attackers love to prey on accounts that have privileges. Reducing privileged accounts and protecting privileged accounts therefore is paramount. Users, groups, and service accounts need to be protected to help protect the entire Active Directory …
This video shows how to use Hyena, from SystemTools Software, to update 100 user accounts from an external text file. View in 1080p for best video quality.

710 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