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.
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
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.
Re: change value NumericUpDown tool
use the if/elseif example. It would work better in this case i believe.
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.
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.
Re: change value NumericUpDown
Quote:
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?