Hello,

I am a student in an independent study class and i am working in vb.NET 2005 trying to create a form that has 3 list boxes and combo boxes that the user can select a package from and see the features that come with that package. The problem that i'm having is that when i clear my form, everything clears out except the combo box. When i clear it, the item choices still need to be there though. Here is what i have so far for that (it's in the upload). If anyone can help me, it is greatly appreciated.

Sincerely,

Struggling Student

The attached file only has shortcuts. Can you attach the project files?

I can't get my form to upload, but here is the code:

Public Class Form1
    Const INTERIOR1_String As String = "Fragrance"
    Const INTERIOR2_String As String = "Shampoo Carpets"
    Const INTERIOR3_String As String = "Shampoo Upholstery"
    Const INTERIOR4_String As String = "Interior Protection Coat"
    Const INTERIOR5_String As String = "Scotchgard"
    Const EXTERIOR1_String As String = "Hand Wash"
    Const EXTERIOR2_String As String = "Hand Wax"
    Const EXTERIOR3_String As String = "Check Engine Fluids"
    Const EXTERIOR4_String As String = "Detail Under Carriage"




    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

    End Sub

    Private Sub packageListBox_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles packageListBox.SelectedIndexChanged
        With Me
            'Clear the lists used for display
            .interiorListBox.Items.Clear()
            .exteriorListBox.Items.Clear()


            'Display the options in a Standard Detail Package
            
            If packageListBox.SelectedIndex = 0 Then
                .interiorListBox.Items.Add(INTERIOR1_String)
                .exteriorListBox.Items.Add(EXTERIOR1_String)

                'Display the options in a Deluxe Detail Package              
            ElseIf packageListBox.SelectedIndex = 1 Then
                .interiorListBox.Items.Add(INTERIOR1_String)
                .interiorListBox.Items.Add(INTERIOR2_String)
                .exteriorListBox.Items.Add(EXTERIOR1_String)
                .exteriorListBox.Items.Add(EXTERIOR2_String)

                'Display the options in a Luxury Detail Package
            ElseIf packageListBox.SelectedIndex = 2 Then
                .interiorListBox.Items.Add(INTERIOR1_String)
                .interiorListBox.Items.Add(INTERIOR2_String)
                .interiorListBox.Items.Add(INTERIOR3_String)
                .exteriorListBox.Items.Add(EXTERIOR1_String)
                .exteriorListBox.Items.Add(EXTERIOR2_String)
                .exteriorListBox.Items.Add(EXTERIOR3_String)

                'Display the options in an Executive Detail Package
            ElseIf packageListBox.SelectedIndex = 3 Then
                .interiorListBox.Items.Add(INTERIOR1_String)
                .interiorListBox.Items.Add(INTERIOR2_String)
                .interiorListBox.Items.Add(INTERIOR3_String)
                .interiorListBox.Items.Add(INTERIOR4_String)
                .exteriorListBox.Items.Add(EXTERIOR1_String)
                .exteriorListBox.Items.Add(EXTERIOR2_String)
                .exteriorListBox.Items.Add(EXTERIOR3_String)
                .exteriorListBox.Items.Add(EXTERIOR4_String)

            End If

        End With
    End Sub

    Private Sub ExitToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ExitToolStripMenuItem.Click
        'End the program

        Me.Close()
    End Sub

    Private Sub ClearToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ClearToolStripMenuItem.Click
        'Clear the fragrance list.


        interiorListBox.Items.Clear()
        exteriorListBox.Items.Clear()

    End Sub
End Class

Ok, here is what I did...

I created a new form and added your code to it. I then created three listboxes with the following names:
Packagelistbox
interiorListbox
ExteriorListbox

I then added the ToolStrip and added the Exit Item and Clear Item

Lastly, I put the following items in the Packagelistbox.

When I select a package, the interior and exterior listboxes are populated with the different options in the packages. When I select clear from the menu, the interior and exterior listboxes are cleared.

My question is, where do the comboboxes come in? Are there three combo boxes? Are they populated during form design (there is no reference to comboboxes in the code)? What are they populated with? What do you want to happen to them?

The combo box contains the fragrances that the user can choose from:
Hawaiian Mist, Baby Powder, Pine, Country Foral, Pina Colada, and Vanilla. There is only one combo box in the problem. What im having trouble with is that everytime i hit clear, i just need it to clear the current selection in the combo box and not the entire list. the combo box was named fragranceComboBox. I tried to use the ComboBox.Items.Clear() but it cleared my entire list.

Ok, here is what I did...

I created a new form and added your code to it. I then created three listboxes with the following names:
Packagelistbox
interiorListbox
ExteriorListbox

I then added the ToolStrip and added the Exit Item and Clear Item

Lastly, I put the following items in the Packagelistbox.

When I select a package, the interior and exterior listboxes are populated with the different options in the packages. When I select clear from the menu, the interior and exterior listboxes are cleared.

My question is, where do the comboboxes come in? Are there three combo boxes? Are they populated during form design (there is no reference to comboboxes in the code)? What are they populated with? What do you want to happen to them?

Ahh... I see. From a VB point of view, what you are trying to do is deselect the item in the combobox, not clear the item.

Try using this:
ComboBox1.SelectedIndex = -1

Since there is no item in the ComboBox with an index of -1, the ComboBox will not have any of the items selected.

should this go in the clear section or in the form part?

This would go in the same place the other two clear statements are located, within the ClearToolStripMenuItem_Click event.

never mind. i got it. I have another question though. We also have to send the information to a printer. Our print option has to send its output to teh print preview window with our name and heading at the top of the report. It has to contain the package name, the interior and exterior items included, and the fragrance selected using a for/next loop. So does this mean i have to just use the print preview dialog box?

anyone who can help please feel free to respond

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.