ComboBox - Disabling Selected Text Logic

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.
RobertFromSecretWeaponsAsked:
Who is Participating?

[Webinar] Streamline your web hosting managementRegister Today

x
 
CodeCruiserConnect With a Mentor Commented:
Try setting focus to some other control such as this

txtName.Focus

This will remove focus from combobox and the blue color.
0
 
Erick37Connect With a Mentor Commented:
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
 
RobertFromSecretWeaponsAuthor Commented:
Excellent.  Thx.  Both solutions would work but from different philosophical perspectives.  

CodeCruisers idea is faster to implement...
0
All Courses

From novice to tech pro — start learning today.