|
-
Oct 16th, 2009, 02:36 PM
#1
Thread Starter
Addicted Member
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.
-
Oct 16th, 2009, 02:42 PM
#2
Fanatic Member
Re: change value NumericUpDown tool
You would use either a select case statement or a bunch of if/elseif statements
for example
vb Code:
if combo1.text = string.empty and combo2.text = string.empty then numericupdown.value = 0 elseif combo1.text <> string.empty and combo2.text = string.empty then 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
-
Oct 16th, 2009, 04:12 PM
#3
Thread Starter
Addicted Member
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.
-
Oct 16th, 2009, 04:39 PM
#4
Fanatic Member
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
-
Oct 16th, 2009, 08:28 PM
#5
Re: change value NumericUpDown tool
Assuming .NET 3.5, I'd suggest using LINQ:
vb.net Code:
Private Sub ComboBoxes_SelectedIndexChanged(ByVal sender As Object, _ ByVal e As EventArgs) Handles ComboBox2.SelectedIndexChanged, _ ComboBox1.SelectedIndexChanged Me.NumericUpDown1.Value = New ComboBox() {Me.ComboBox1, Me.ComboBox2}.Count(Function(cb) cb.SelectedItem IsNot Nothing) End Sub
That creates an arry of the ComboBoxes and gets the count of the items in that array whose SelectedItem isn't Nothing.
-
Oct 20th, 2009, 09:53 AM
#6
Thread Starter
Addicted Member
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.
-
Oct 20th, 2009, 06:18 PM
#7
Re: change value NumericUpDown
 Originally Posted by eugz
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?
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|