Results 1 to 8 of 8

Thread: ComboBox - Please help!

  1. #1
    Join Date
    Apr 2012
    Location
    St. Louis, Missouri
    Posts
    383
    Mentioned
    2 Post(s)
    Quoted
    1 Post(s)

    Default ComboBox - Please help!

    Ok so i'm taking my first programming class in college, CMIS 142, programming in visual basic.

    We have only had two labs , and all we've really learned how to do is code for click button events, check boses, and how to display output into text boxes.

    Just for fun I've decided to build my own little equipment builder. It will have no real use besides to make it for fun. Here is what it looks like:


    What I want it to do is, have like maybe two different choices in each drop down box. When I select the choice, I'm going to have a picture box for each item, that is over the main picture box (that you can see). It will be set to "not visible" to start off with, then when the item is selected from the combo box, I want it to then " = helmofnetiznotPictureBox.visible".

    That way when it is selected, the picture will become visible and look as if it is "equipped".

    Later on I'll be playing with the math to get the stats displayed in the display only text box under that main picturebox, but for now i'm stuck.

    I got those things in the combo box list just by hitting "edit items" in the combo box little menu. But how do I code for the specific things that are in the combo box drop down box?

    Like I said, I want to select one and have it make the picture visible.

    I know for like a checkbox it would be "HelmofneitiznotCheckbox.checked = HelmofneitiznotPicturebox.visible"

    But I want to have more then one option available, hence the combobox and not the checkbox. No experience with combo boxes, please help!

    edit: also hopefully if someone can help me with that first, what method do I use to "clear" my combo boxes? I want my "Resetbutton" to return them to their blank default, but not sure how..

  2. #2
    Join Date
    Jan 2008
    Location
    C:\
    Posts
    1,483
    Mentioned
    2 Post(s)
    Quoted
    2 Post(s)

    Default

    I don't know much about vb... but hopefully an analogy can help you out If you can check the "caption" (not entirely sure what it would be called in vb) then you could do something like:

    Simba Code:
    // Assuming your ComboBoxes are stored in an array
    if (ComboBoxes[0].caption = Lowercase('helm of neitiznot')) then
      HelmofneitiznotPicturebox.visible;

    And to clear it would be something alone the lines of:

    Simba Code:
    for i := 0 to 10 do
      ComboBoxes[i].caption := '';

    Of course, this is all assuming that caption refers to the current value

  3. #3
    Join Date
    Apr 2012
    Location
    St. Louis, Missouri
    Posts
    383
    Mentioned
    2 Post(s)
    Quoted
    1 Post(s)

    Default

    Quote Originally Posted by Runaway View Post
    I don't know much about vb... but hopefully an analogy can help you out If you can check the "caption" (not entirely sure what it would be called in vb) then you could do something like:

    Simba Code:
    // Assuming your ComboBoxes are stored in an array
    if (ComboBoxes[0].caption = Lowercase('helm of neitiznot')) then
      HelmofneitiznotPicturebox.visible;

    And to clear it would be something alone the lines of:

    Simba Code:
    for i := 0 to 10 do
      ComboBoxes[i].caption := '';

    Of course, this is all assuming that caption refers to the current value
    That was wayyy over my head . VisualBasic is very... basic .

    It's really prebuilt. All I really know how to do is when I want to code for something, i.e. the reset button, I double click on it. Then it brings me to the code, and it shows the code for if that click event is fired. Then I just type my remarks and type things simply. I have really never done any "if then" or any other "statements"

    The only "code" I have done for that whole thing is..

    SCAR Code:
    Public Class Form1

       Private Sub ResetButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ResetButton.Click
          'Reset's the combo boxes for all equipment
            '(make sure resetting all combo boxes to default also resets the pictures associated with them to not visible too)
            StatsTextBox.Clear()

        End Sub
    End Class

    ^The top part is put there from me double clicking (or "firing") the click even, the reset button. Then the green of obviously my remarks, and the only "coding" I've done was to clear the textbox when I hit the reset button, which is the .Clear method I used. I'll have to include whatever methods to clear the combo boxes in that sub, but Idk how

  4. #4
    Join Date
    Jun 2008
    Location
    United States
    Posts
    818
    Mentioned
    60 Post(s)
    Quoted
    90 Post(s)

    Default

    I know when making a form in Simba, there's an "ItemIndex" property, which returns the current selected item in your combobox, so if you had two items, it would return 0 or 1 depending on which item is currently selected.
    [10/14/13:19:03] <BenLand100> this is special relatively, just cleverly disguised with yachts

  5. #5
    Join Date
    Apr 2012
    Location
    St. Louis, Missouri
    Posts
    383
    Mentioned
    2 Post(s)
    Quoted
    1 Post(s)

    Default

    Quote Originally Posted by euphemism View Post
    I know when making a form in Simba, there's an "ItemIndex" property, which returns the current selected item in your combobox, so if you had two items, it would return 0 or 1 depending on which item is currently selected.
    Ok I'll poke around a bit and see what I can find, thanks!

    edit: I did find a property of the Combobox named "Items", and then you click the "collection" and that has the list of stuff I added the other way, so I can add it that way. I'm just not sure how to refer to an item in my combo box, when trying to code for it.

    Hopefully Kyle takes a look at this, I think i remember reading he was good at VB.
    Last edited by Luke L; 09-12-2012 at 12:52 AM.

  6. #6
    Join Date
    Jun 2008
    Location
    United States
    Posts
    818
    Mentioned
    60 Post(s)
    Quoted
    90 Post(s)

    Default

    ComboBox.SelectedIndex returns the index of the currently selected item.
    [10/14/13:19:03] <BenLand100> this is special relatively, just cleverly disguised with yachts

  7. #7
    Join Date
    Feb 2011
    Location
    The Future.
    Posts
    5,600
    Mentioned
    396 Post(s)
    Quoted
    1598 Post(s)

    Default

    VisualBasic Code:
    If ComboBox.SelectedValue IsNot Nothing Then
       PictureBox.Image = ImageFromFile("C:/Brandon/Desktop/" & ComboBox.SelectedItem.ToString & ".bmp")

    I think? I haven't done VB in basically years lol.

    Or you can try iterating with a for loop and checking if the index is the same as the index of a picture. Load that picture into the thing I guess.
    I am Ggzz..
    Hackintosher

  8. #8
    Join Date
    Apr 2012
    Location
    St. Louis, Missouri
    Posts
    383
    Mentioned
    2 Post(s)
    Quoted
    1 Post(s)

    Default

    I figured it out!

    Code:
    Public Class Form1
        
        Private Sub NameComboBox_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles NameComboBox.SelectedIndexChanged
            If HelmetComboBox.SelectedItem = "Verac's Helm" Then
                VeracsHelmPictureBox.Visible = True
            Else
                VeracsHelmPictureBox.Visible = False
            End If
        End Sub
    End Class
    That works so that when an item is selected in my combobox drop down it makes that item visible, but if another item is selected then it will go back to not visible, hence giving it the "unequip" effect.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •