Question Combo Box change in selection

ExpoSport

Member
Joined
Jun 6, 2009
Messages
12
Programming Experience
Beginner
ok, got a question here, two really. first i'll ask the hard one, as i think i have my other one out of the way so i'll save it for later :p but i made a program where a user enters in dimensions in several text boxes in inches. there are radio boxes that the user decides what thickness of wood they would like to use. what i'd like to do is add metric into the program and use two combo boxes. one combo box drops down and you can select inches, centimeters, or millimeters. the other one drops down to choose the thickness of the wood.

ok now here's my question. say i pick inches in the first combo box, i'd like the second one to display only the thickness of the wood in inches, no metric. if i pick centimeters, i'd like the second combo box to display the thickness of the wood in only centimeters, no millimeters or inches. and the same goes for millimeters.

i also have the program on a timer that runs at 100 milliseconds so the user can quickly see the differences in dimensions they put in instead of having to hit the calculate button over and over and over (not sure if that really matters or not, had a couple issues with the boxes earlier but don't think it was timer related now)

but is this possible? basically just looking for the kinds of drop boxes that you see on a page like autotrader.com where you select dodge, and then only the dodge cars are listed, select chevy and the chevy cars are listed, etc. thanks for any help in advance :)
 
I would disable the second combo box until the user selects the desired "thickness of wood". Then, enable the second combo box and fill it with the desired choices in code.
 
makes sense. that's still the tricky part lol. i've only taken one semester of visual basic and have never worked with combo boxes so they're new to me. i guess i'll look around in some examples if i can find any
 
Sorry for the delayed reply. Been busy with some web pages.

Anyway, here's some simple code to give you the idea:
VB.NET:
Public Class Form1

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

        Me.cboFirst.Items.Add("One")
        Me.cboFirst.Items.Add("Two")

        Me.cboSecond.Enabled = False

    End Sub

    Private Sub cboFirst_TextChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles cboFirst.TextChanged

        Me.cboSecond.Enabled = True

        If Me.cboFirst.Text = "One" Then
            Me.cboSecond.Items.Add("OneOne")
            Me.cboSecond.Items.Add("OneTwo")
        Else
            Me.cboSecond.Items.Add("TwoOne")
            Me.cboSecond.Items.Add("TwoTwo")
        End If

    End Sub

End Class
 
hey thanks! i've been busy with some other projects as well. i can usually only code/do homework at night. while it's still nice out at least. did a majority of my homework yesterday so hopefully i can hop onto this again tonight. i'll tinker around with it and report with what i get. thanks again!
 
works like a charm! just had to put in a clear statement after each elseif statement or else the info in the combo box would stack on each other. easy fix tho. thanks again for the help, it's much appreciated!

i'm going to have questions on a couple other things too... haha. but i'll save those for other threads when i come to it
 
it sounds like you ony want ONE combo box, if the second combo will always copy the value of the first?

Dont use a timer on short intervals, use the TextChanged event instead, and recalculate every time the text in a text box changes

-

the second thing you discuss is called most often "cascading comboboxes" - do a google search for that
 
i need 2 boxes. the first one the user will pick inches, centimeters, or millimeters. then what they pick will decide how the wood thickness in the second combo box will be displayed. but i like that you brought up the textchanged event. i will look into that as well as the cascading comboboxes. thank you cjard
 
Back
Top