Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Rhinorhino on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Combobox reset for next instance

Status
Not open for further replies.

lunaclover

Programmer
Joined
Jun 22, 2005
Messages
54
Hi - my code is filled with "if then else" statements in it, as the program I'm writing has many exceptions and combinations of selections between radiobuttons, textboxes and comboboxes. I have a combobox that I want to empty its contents from a previous selection, and refill with new contents.
For example, part of my code reads..
If rb1.checked then
If rb2.Checked Then
cb1.Items.Add("1.5")
cb1.Items.Add("2.0")
cb1.Items.Add("2.5")
cb1.Items.Add("3.0")

.
.
.

If rb3.Checked Then
cb1.Items.Add("2.5")
cb1.Items.Add("3.5")
cb1.Items.Add("4")
cb1.Items.Add("5")

and so on for about 9 different scenerios, (with more nested if statments inside(where the ... are)).

When running the program and selections are made and changed, the combo box items are added each time so it just adds the items over and over again, so they are all listed x number of times. When I used the cb1.items.clear() in each nested if statement, it works, and you can pull the drop-down menu down and see the options specific to that scenerio, but when you select one and the drop-down list closes, the selection doesn't stay in the box. It just goes empty. I have tried cb1.dispose(), cb1.refresh().. not sure what to do because clear() isn't letting me select anything when it's in the code.

To summarize - I am looking to find out which command I can use that will clear the contents of a combobox in order to fill it with the correct options depending on the combination of buttons a user may select. And be able to select it afterwards.

Thanks to anybody who can help. I am still very new and learning, so may have looked over something simple.

Luna
 
No, unless I'm looking at the wrong thing - I inserted a breakpoint and then F11ed through it.. nothing unusual.

If you want me to do something else to help you help me please tell me how and I will.. : )

Thanks,
Leah
 
I'm trying to figure out when the text(Not the list) gets cleared.

If I understand you, it's current behavior is:

clear combobox list
populate combo box list
User selects an option from the combo box
text is immediately cleared

?

If so, there must be some code that fires when the user makes the selection. Either in combobox.selectedindexchanged or a mouse/key event or something of the like.

-Rick

VB.Net Forum forum796 forum855 ASP.NET Forum
[monkey]I believe in killer coding ninja monkeys.[monkey]
 
Rick - you are the coolest. I was stuck blaming it all on the clear() command this whole time.

I checked and I had rb2.selectedvaluechanged under the handle - I removed it and put the clears back in and it works fine! I added it there because I thought I had to in order to make it even do anything to that control.

Thank you so much - sorry I am still too new to think of everything at first.

 
Rick - I just remembered why I added it in the first place.

If rb1.Checked = True Then
rb2.Items.Clear()
rb2.Items.Add("1.5")
rb2.Items.Add("2.0")
rb2.Items.Add("2.5")
rb2.Items.Add("3.0")
rb2.Items.Add("3.5")
rb2.Items.Add("4.0")
rb2.Items.Add("5.0")
If (cb1.Text >= "3.0") Then
rb10.Enabled = True
rb11.Enabled = True
rb12.Enabled = True
rb13.Enabled = True
rb14.Enabled = True
rb15.Enabled = True
Else
rb10.Enabled = True
rb11.Enabled = True
rb12.Enabled = False
rb13.Enabled = False
rb14.Enabled = False
rb15.Enabled = False
End If
End If

see, don't I have to keep the cb1 in the handle to make it listen to this code? If so, maybe cb1.selectedvaluechanged isn't the best.. I will keep trying but wanted to let you know why I did it.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top