ComboBox, Don't want selected item highlighted

  • (2 Pages)
  • +
  • 1
  • 2

18 Replies - 13522 Views - Last Post: 04 April 2009 - 03:15 PM Rate Topic: -----

#1 jimdandy75  Icon User is offline

  • D.I.C Regular

Reputation: 37
  • View blog
  • Posts: 311
  • Joined: 30-June 08

ComboBox, Don't want selected item highlighted

Post icon  Posted 04 April 2009 - 08:07 AM

Hello, this is probably simple, but I have googled and looked through my Murach's and I can't seem to find the solution.
I have a combo box that's populated with 4 or 5 items, when you select the item, it shows in the combobox and is
highlighted. How do I get it to show without being highlighted?

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
		CBgrocerys.Text = "Select an item...."
		Dim item() As String = {"apples", "oranges>", _
							   "pears", "plums"}

		For Each thing As String In item
			CBgrocerys.Items.Add(thing)
		Next
	End Sub



Thank you :D

This post has been edited by jimdandy75: 04 April 2009 - 08:15 AM


Is This A Good Question/Topic? 0
  • +

Replies To: ComboBox, Don't want selected item highlighted

#2 _HAWK_  Icon User is offline

  • Master(Of Foo)
  • member icon

Reputation: 1053
  • View blog
  • Posts: 4,081
  • Joined: 02-July 08

Re: ComboBox, Don't want selected item highlighted

Posted 04 April 2009 - 09:29 AM

In the CBgrocerys_SelectedIndexChanged event - where you are handling what happens where the user selects an item add this to the end:

Private Sub CBgrocerys_SelectedIndexChanged('...
   'code to handle the selected item/index then
 CBgrocerys.SelectedIndex = -1
End Sub


This post has been edited by hawkvalley1: 04 April 2009 - 09:32 AM

Was This Post Helpful? 0
  • +
  • -

#3 PsychoCoder  Icon User is offline

  • Google.Sucks.Init(true);
  • member icon

Reputation: 1641
  • View blog
  • Posts: 19,853
  • Joined: 26-July 07

Re: ComboBox, Don't want selected item highlighted

Posted 04 April 2009 - 09:32 AM

Try

CBgrocerys.SelectedIndex = -1


Was This Post Helpful? 0
  • +
  • -

#4 jimdandy75  Icon User is offline

  • D.I.C Regular

Reputation: 37
  • View blog
  • Posts: 311
  • Joined: 30-June 08

Re: ComboBox, Don't want selected item highlighted

Posted 04 April 2009 - 09:38 AM

Thanks for the reply, but when I add that to CBgrocerys_SelectedIndexChanged event,
and select an item the dropdown, the textbox just goes completely blank. I want it to show
the text for the item just not highlighted. :wink:
Was This Post Helpful? 0
  • +
  • -

#5 PsychoCoder  Icon User is offline

  • Google.Sucks.Init(true);
  • member icon

Reputation: 1641
  • View blog
  • Posts: 19,853
  • Joined: 26-July 07

Re: ComboBox, Don't want selected item highlighted

Posted 04 April 2009 - 09:51 AM

Oh I see. Well in that case you're probably going to have to write your own custom control that inherits from the ComboBox and override the paint method to remove that.
Was This Post Helpful? 0
  • +
  • -

#6 jimdandy75  Icon User is offline

  • D.I.C Regular

Reputation: 37
  • View blog
  • Posts: 311
  • Joined: 30-June 08

Re: ComboBox, Don't want selected item highlighted

Posted 04 April 2009 - 09:55 AM

Hey Hawk, you said :
Private Sub CBgrocerys_SelectedIndexChanged('...
   'code to handle the selected item/index then
 CBgrocerys.SelectedIndex = -1
End Sub



I don't have any code in CBgrocerys_SelectedIndexChanged for the selected item,
when I select an item from the dropdown it appears in the combobox but is highlighted.
I didn't have to add any additional code to CBgrocerys_SelectedIndexChanged to do
this.

Psycho, that sounds complicated !!! Maybe this isn't an easy little fix,
I'll just throw in the hat and move on :wacko:
Was This Post Helpful? 0
  • +
  • -

#7 jimdandy75  Icon User is offline

  • D.I.C Regular

Reputation: 37
  • View blog
  • Posts: 311
  • Joined: 30-June 08

Re: ComboBox, Don't want selected item highlighted

Posted 04 April 2009 - 11:31 AM

I think I thought of a fairly easy way to make this happen ???!!! OK, maybe.......
Just moving the cursor makes the highlight go away. This code gives me an error
on Selectionstart, but if I had a little help I think it would do.

Private Sub CBgrocerys_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CBgrocerys.SelectedIndexChanged
		If CBgrocerys.Text = ("apples", "oranges", "pears", "plums") Then
			CBgrocerys.Selectionstart = CBgrocerys.Text.IndexOf("(" + "{", 7)
		End If
	End Sub



Thanks again :D
Was This Post Helpful? 0
  • +
  • -

#8 jimdandy75  Icon User is offline

  • D.I.C Regular

Reputation: 37
  • View blog
  • Posts: 311
  • Joined: 30-June 08

Re: ComboBox, Don't want selected item highlighted

Posted 04 April 2009 - 01:30 PM

Well I have tried at least 20 different codes in:
Private Sub CBgrocerys_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CBgrocerys.SelectedIndexChanged



and I get nothing :angry:
I can't get rid of the highlight or move the cursor in efforts to get rid of the highlight.

I'm open to any ideas :D
Was This Post Helpful? 0
  • +
  • -

#9 aceofspades686  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: 6
  • View blog
  • Posts: 334
  • Joined: 08-October 07

Re: ComboBox, Don't want selected item highlighted

Posted 04 April 2009 - 01:36 PM

This is just at a quick glance, but what about setting the textbox, then changing the selection and keeping it from changing the textbox when its at -1.

If Not CBgrocerys.SelectedIndex = -1 Then
   //Write the value to textbox
  CBgrocerys.SelectedIndex = -1
EndIf



This may not work, just the first thing that came to mind for me.
Was This Post Helpful? 0
  • +
  • -

#10 jimdandy75  Icon User is offline

  • D.I.C Regular

Reputation: 37
  • View blog
  • Posts: 311
  • Joined: 30-June 08

Re: ComboBox, Don't want selected item highlighted

Posted 04 April 2009 - 01:52 PM

Thanks for looking at this Aceofspades, but that just made all the text disappear in the combobox
when you select the item. :/
Was This Post Helpful? 0
  • +
  • -

#11 aceofspades686  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: 6
  • View blog
  • Posts: 334
  • Joined: 08-October 07

Re: ComboBox, Don't want selected item highlighted

Posted 04 April 2009 - 01:59 PM

Hm.. not sure what would've caused that, when you said that I decided to actually fire up VB and try it out, and it worked (assuming I understand what you were trying to do)

I left the controls with their default names.
	Private Sub ComboBox1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ComboBox1.SelectedIndexChanged
		If Not (ComboBox1.SelectedIndex = -1) Then
			TextBox1.Text = ComboBox1.SelectedItem.ToString
			ComboBox1.SelectedIndex = -1
		End If
	End Sub


Was This Post Helpful? 0
  • +
  • -

#12 June7  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 104
  • View blog
  • Posts: 904
  • Joined: 09-December 08

Re: ComboBox, Don't want selected item highlighted

Posted 04 April 2009 - 02:20 PM

I tried to accomplish this with VBA behind Access form. Don't seem to have the SelectedIndexChanged event available. Best I could come up with was to move the cursor to end of text. However, the Change event causes problem when trying to type in an entry and the AfterUpdate event would not fire when selection made from dropdown list. It's a catch22 for me but if VB has the SelStart method maybe it would work in the SelectedIndexChanged event.

Private Sub Combo0_Change()
Me.Combo0.SelStart = Len(Me.Combo0) + 1
End Sub


This post has been edited by June7: 04 April 2009 - 02:45 PM

Was This Post Helpful? 0
  • +
  • -

#13 jimdandy75  Icon User is offline

  • D.I.C Regular

Reputation: 37
  • View blog
  • Posts: 311
  • Joined: 30-June 08

Re: ComboBox, Don't want selected item highlighted

Posted 04 April 2009 - 02:23 PM

Ace,
This will work if I introduce the new textbox.
But what I was trying to accomplish, is to have the text that shows in CBgrocerys (combobox)
to not be highlighted when the item from the dropdown is selested.
So if I select "pears" and then want to add "- 2 bags" before hitting the button to add it to my list it will then say "Pears - 2 bags".
The problem with it staying highlighted is that if you try to type any additional information
it starts at the beginning of the box and wipes out the selected item. :blink:

June, I just get an error when I try that code

This post has been edited by jimdandy75: 04 April 2009 - 02:28 PM

Was This Post Helpful? 0
  • +
  • -

#14 aceofspades686  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: 6
  • View blog
  • Posts: 334
  • Joined: 08-October 07

Re: ComboBox, Don't want selected item highlighted

Posted 04 April 2009 - 02:32 PM

Oh, okay. I thought you meant you wanted to clear the item that was selected from the combo box (return to the default blank position) and just copy that value to somewhere else. My fault >.<

See if changing the DropDownStyle from DropDown to DropDownList suits your purposes. If not, then odds being you may have to create a custom control like PsychoCoder suggested.

Edit Upon reading the problem again, I have a feeling this still won't do what you're looking for. If it were me in this case, I would do like AdamSpeight2008 suggests below and make a separate text box for the quantity, then just concatenate the strings before adding them to the list.

This post has been edited by aceofspades686: 04 April 2009 - 02:42 PM

Was This Post Helpful? 0
  • +
  • -

#15 AdamSpeight2008  Icon User is offline

  • MrCupOfT
  • member icon


Reputation: 2262
  • View blog
  • Posts: 9,464
  • Joined: 29-May 08

Re: ComboBox, Don't want selected item highlighted

Posted 04 April 2009 - 02:36 PM

Why not consider enter the quantity and differ textbox?
Was This Post Helpful? 0
  • +
  • -

  • (2 Pages)
  • +
  • 1
  • 2