Results 1 to 7 of 7

Thread: change value NumericUpDown

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Nov 2006
    Posts
    176

    change value NumericUpDown

    Hi All.
    In my has 2 ComboBox fields and 1 NumericUpDown field. I would like change value NumericUpDown in depend of value in Combobox.
    1. if ComboBox1 and ComboBox2 is empty NumericUpDown = 0
    2. if ComboBox1 has some value and ComboBox2 is empty NumericUpDown = 1
    3. if ComboBox1 is empty and ComboBox2 has some value NumericUpDown = 1
    4. if ComboBox1 has some value and ComboBox2 has some value NumericUpDown = 2
    If it is possiable how to do it?
    Thanks.
    Last edited by eugz; Oct 20th, 2009 at 11:03 AM.

  2. #2
    Fanatic Member
    Join Date
    Aug 2009
    Posts
    540

    Re: change value NumericUpDown tool

    You would use either a select case statement or a bunch of if/elseif statements

    for example

    vb Code:
    1. if combo1.text = string.empty and combo2.text = string.empty then
    2. numericupdown.value = 0
    3. elseif combo1.text <> string.empty and combo2.text = string.empty then
    4. numericupdown.value = 1

    etc
    Where I'm from we only have one bit of advice for new comers: "If you hear banjos, turn and run".


    VS 2008 .NetFW 2.0

  3. #3

    Thread Starter
    Addicted Member
    Join Date
    Nov 2006
    Posts
    176

    Re: change value NumericUpDown

    I code procedure for combo1 like:
    Code:
    Private Sub ComboBox1_SelectedValueChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles ComboBox1.SelectedValueChanged
            Select Case Me.ComboBox1.SelectedValue
                Case ""
                    Me.NumericUpDown1.Value = 0
                Case Else
                    Me.NumericUpDown1.Value = 1
            End Select
    End Sub
    That works only for ComboBox1. How to create procedure to change NumericUpDown1 value if it value depentds from changes of both ComboBox?
    Thanks.
    Last edited by eugz; Oct 20th, 2009 at 11:03 AM.

  4. #4
    Fanatic Member
    Join Date
    Aug 2009
    Posts
    540

    Re: change value NumericUpDown tool

    use the if/elseif example. It would work better in this case i believe.
    Where I'm from we only have one bit of advice for new comers: "If you hear banjos, turn and run".


    VS 2008 .NetFW 2.0

  5. #5
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: change value NumericUpDown tool

    Assuming .NET 3.5, I'd suggest using LINQ:
    vb.net Code:
    1. Private Sub ComboBoxes_SelectedIndexChanged(ByVal sender As Object, _
    2.                                             ByVal e As EventArgs) Handles ComboBox2.SelectedIndexChanged, _
    3.                                                                           ComboBox1.SelectedIndexChanged
    4.     Me.NumericUpDown1.Value = New ComboBox() {Me.ComboBox1, Me.ComboBox2}.Count(Function(cb) cb.SelectedItem IsNot Nothing)
    5. End Sub
    That creates an arry of the ComboBoxes and gets the count of the items in that array whose SelectedItem isn't Nothing.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  6. #6

    Thread Starter
    Addicted Member
    Join Date
    Nov 2006
    Posts
    176

    Re: change value NumericUpDown

    Thank for replays.
    Thanks jmcilhinney. I tried to use your code and when I select any value form ComboBox1 or ComboBox2 the NumericUpDown control get value 2.
    In my case each ComboBox has range 0-3.
    ComboBox1 has three value. for instance, AAA, BBB, CCC
    ComboBox2 has three value. for instance, DDD, EEE, FFF
    The NumericUpDown should has range 0-6 sum of both ComboBox.
    For instance, if user select from ComboBox1 AAA and from ComboBox2 EEE the NumericUpDown should display value 5.
    If it possible how to do it?
    Thanks.
    Last edited by eugz; Oct 20th, 2009 at 11:04 AM.

  7. #7
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: change value NumericUpDown

    Quote Originally Posted by eugz View Post
    Thank for replays.
    Thanks jmcilhinney. I tried to use your code and when I select any value form ComboBox1 or ComboBox2 the NumericUpDown control get value 2.
    In my case each ComboBox has range 0-3.
    ComboBox1 has three value. for instance, AAA, BBB, CCC
    ComboBox2 has three value. for instance, DDD, EEE, FFF
    The NumericUpDown should has range 0-6 sum of both ComboBox.
    For instance, if user select from ComboBox1 AAA and from ComboBox2 EEE the NumericUpDown should display value 5.
    If it possible how to do it?
    Thanks.
    That is NOT what you asked for in the first place. If you don't explain clearly and fully what it is you want then it's unlikely that we can provide a solution that will work.

    Also, in your case, the value in the NUD would be the same for various combinations of selections in the ComboBoxes. Is that OK?
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

Posting Permissions

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



Click Here to Expand Forum to Full Width