Results 1 to 6 of 6

Thread: Help needed in Visual Basic 2010, WinForms, ComboBox

  1. #1
    Registered+
    Join Date
    Sep 2012
    Location
    United Kingdom
    Posts
    28
    Thanks
    1
    Thanked
    1 time in 1 post
    • Cumminsc9's system
      • Motherboard:
      • Gigabyte z77-DS3H
      • CPU:
      • Intel i5 @3.30Ghz
      • Memory:
      • 8Gb DRR3 Corsair
      • Storage:
      • OCZ Agility3 240GB & 1TB Seagate
      • Graphics card(s):
      • AMD Radeon HD 6800
      • Case:
      • NZXT Phantom
      • Operating System:
      • Windows 7 Ultimate 64bit

    Question Help needed in Visual Basic 2010, WinForms, ComboBox

    So here I have an interesting question.

    I'm in the process of creating a Football Results Entry form. So far I have one method of inputting results from a football match but I need another way. I thought of using Combo boxes for both teams. So let me give you a quick rundown of what I am attempting to do.

    So I have a text box that you enter your teams into, then that makes the next step visible where you enter the results for the teams. Now I have 2 combo boxes one for each team that will need the values of
    >Win for team
    >Loss for team
    >Draw for teams
    >Game cancelled

    So what I need to do is program if you were to select "Win for team" then the label under that would show "3points to home team" for example and say for loss "0points to Home Team" I know there is code out there for it cause I can't be the first one who wants a combo box to display a different value when the correct display value is selected.

    I hope I've made it clear as possible. If needed I'll be happy to add more information.

    Thanks
    Tom

  2. #2
    Member
    Join Date
    Sep 2012
    Location
    Worksop
    Posts
    149
    Thanks
    1
    Thanked
    15 times in 13 posts
    • KrisWragg's system
      • Motherboard:
      • Asrock X370 Taichi
      • CPU:
      • AMD 1700X @ 3.7Ghz
      • Memory:
      • 32GB Corsair Vengeance
      • Storage:
      • 500GB 950 Evo + 500GB 850 Evo
      • Graphics card(s):
      • R9 290 @ 1.1Ghz
      • PSU:
      • Seasonic Platinum 660W
      • Case:
      • Fractal Design Define S
      • Operating System:
      • Windows 10 Pro 64bit
      • Monitor(s):
      • 2 x Dell U2713HM
      • Internet:
      • Plusnet 78mbit down / 20mbit up

    Re: Help needed in Visual Basic 2010, WinForms, ComboBox

    To do this you will want to register for the SelectedIndexChanged event on the combobox:
    http://msdn.microsoft.com/en-us/libr...exchanged.aspx

    When you have done that then you can use a switch statement based on the SelectedIndex of the combobox to set the correct text of your label below it

  3. #3
    Member
    Join Date
    Sep 2012
    Location
    Worksop
    Posts
    149
    Thanks
    1
    Thanked
    15 times in 13 posts
    • KrisWragg's system
      • Motherboard:
      • Asrock X370 Taichi
      • CPU:
      • AMD 1700X @ 3.7Ghz
      • Memory:
      • 32GB Corsair Vengeance
      • Storage:
      • 500GB 950 Evo + 500GB 850 Evo
      • Graphics card(s):
      • R9 290 @ 1.1Ghz
      • PSU:
      • Seasonic Platinum 660W
      • Case:
      • Fractal Design Define S
      • Operating System:
      • Windows 10 Pro 64bit
      • Monitor(s):
      • 2 x Dell U2713HM
      • Internet:
      • Plusnet 78mbit down / 20mbit up

    Re: Help needed in Visual Basic 2010, WinForms, ComboBox

    Actually I tried this out and its a bit harder than I thought... anyway I've got something that should work for you, hopefully you can understand it and modify it to your needs. Let me know if you get stuck!
    Code:
            public Form1()
            {
                InitializeComponent();
    
                DataTable dt = new DataTable();
                dt.Columns.Add("Result", typeof(string));
                dt.Columns.Add("Points", typeof(string));
    
                dt.Rows.Add(new string[]{"Win", "3 points"});
                dt.Rows.Add(new string[] { "Lose", "0 points" });
                dt.Rows.Add(new string[] { "Draw", "1 points" });
                dt.Rows.Add(new string[] { "Cancelled", "0 points" });
    
                this.comboBox1.DropDown += new System.EventHandler(this.comboBox1_DropDown);
                this.comboBox1.SelectedIndexChanged += new System.EventHandler(this.comboBox1_SelectedIndexChanged);
    
                comboBox1.DataSource = dt;
                comboBox1.DisplayMember = "Points";
            }
    
            private void comboBox1_DropDown(object sender, EventArgs e)
            {
                comboBox1.DisplayMember = "Result";
            }
    
            private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
            {
                int nSel = comboBox1.SelectedIndex;
                comboBox1.DisplayMember = "Points";
                comboBox1.SelectedIndex = nSel;
            }
    Last edited by KrisWragg; 27-09-2012 at 01:33 PM. Reason: adding code tags

  4. #4
    Registered+
    Join Date
    Sep 2012
    Location
    United Kingdom
    Posts
    28
    Thanks
    1
    Thanked
    1 time in 1 post
    • Cumminsc9's system
      • Motherboard:
      • Gigabyte z77-DS3H
      • CPU:
      • Intel i5 @3.30Ghz
      • Memory:
      • 8Gb DRR3 Corsair
      • Storage:
      • OCZ Agility3 240GB & 1TB Seagate
      • Graphics card(s):
      • AMD Radeon HD 6800
      • Case:
      • NZXT Phantom
      • Operating System:
      • Windows 7 Ultimate 64bit

    Re: Help needed in Visual Basic 2010, WinForms, ComboBox

    Hey KrisWragg

    Thanks for contribution and sorry for my late response however, I managed to do this without the long and complicated code above. I used "Select Case" instead. Regardless I will still look at your code and have a go with it. Thanks for your help.

    Code:
            Select Case (cbTeam1.SelectedIndex)
                Case 0
                    lblfinalresults1.Text = "3 Points"
                    lblFinalresults2.Text = "0 Points"
                Case 1
                    lblFinalresults2.Text = "3 Points"
                    lblfinalresults1.Text = "0 Points"
                Case 2
    
                Case 3
                    lblfinalresults1.Text = "1 Point"
                    lblFinalresults2.Text = "1 Point"
                Case 4
    
                Case 5
                    lblfinalresults1.Text = "Game Cancelled"
                    lblFinalresults2.Text = "Game Cancelled"
                    MsgBox("Game to be rescheduled")
                Case 6
    
                Case 7
                    lblfinalresults1.Text = Nothing
                    lblFinalresults2.Text = Nothing
    
            End Select
    Oh but now I have a new issue. If you want to have a bash at it before I figure something out ;P

  5. #5
    Member
    Join Date
    Sep 2012
    Location
    Worksop
    Posts
    149
    Thanks
    1
    Thanked
    15 times in 13 posts
    • KrisWragg's system
      • Motherboard:
      • Asrock X370 Taichi
      • CPU:
      • AMD 1700X @ 3.7Ghz
      • Memory:
      • 32GB Corsair Vengeance
      • Storage:
      • 500GB 950 Evo + 500GB 850 Evo
      • Graphics card(s):
      • R9 290 @ 1.1Ghz
      • PSU:
      • Seasonic Platinum 660W
      • Case:
      • Fractal Design Define S
      • Operating System:
      • Windows 10 Pro 64bit
      • Monitor(s):
      • 2 x Dell U2713HM
      • Internet:
      • Plusnet 78mbit down / 20mbit up

    Re: Help needed in Visual Basic 2010, WinForms, ComboBox

    What you've done is what I thought you initially wanted, then I thought you wanted the text in the combobox, which makes it a bit more difficult

    I can have a look at your other problem if you want, no use banging your head against a wall if someone knows the answer

  6. #6
    Registered+
    Join Date
    Sep 2012
    Location
    United Kingdom
    Posts
    28
    Thanks
    1
    Thanked
    1 time in 1 post
    • Cumminsc9's system
      • Motherboard:
      • Gigabyte z77-DS3H
      • CPU:
      • Intel i5 @3.30Ghz
      • Memory:
      • 8Gb DRR3 Corsair
      • Storage:
      • OCZ Agility3 240GB & 1TB Seagate
      • Graphics card(s):
      • AMD Radeon HD 6800
      • Case:
      • NZXT Phantom
      • Operating System:
      • Windows 7 Ultimate 64bit

    Re: Help needed in Visual Basic 2010, WinForms, ComboBox

    Haha yeah upon reading through what I wanted it wasn't exceptionally clear. Sorry about that.

    Anyways my new problem is how would I effectively use the keystroke command to send characters to an external program such as; notepad, or word. Any idea KirsWragg?

    Regards

Thread Information

Users Browsing this Thread

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

Tags for this Thread

Posting Permissions

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