Click here to Skip to main content
15,861,172 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hello CodeProject community!
I have a problem with my codes.
When user clicking the same item from ComboBox control.
The NumericUpDown value will repeat the calculation.
So how do I prevent the calculation when user choose the same item in ComboBox control?

I hope you all can help me and sorry for my bad grammar.
Thank you.

What I have tried:

For more understanding about my current problem, below is my code for the ComboBox control

Private Sub ComboBox2_SelectedIndexChanged(sender As Object, e As EventArgs) Handles ComboBox2.SelectedIndexChanged
'Change speed translator unit
If ComboBox2.SelectedItem = "KB/s" Then
NumericUpDown2.DecimalPlaces = 0
NumericUpDown2.Increment = 1
TranferRateSpeedKBs.Enabled = True
TranferRateSpeedMBs.Enabled = False

'My problem [I want to prevent the calculation if user has selected same option in combobox]
NumericUpDown2.Value = NumericUpDown2.Value * 1000

ElseIf ComboBox2.SelectedItem = "MB/s" Then
NumericUpDown2.DecimalPlaces = 2
NumericUpDown2.Increment = 0.01
TranferRateSpeedKBs.Enabled = False
TranferRateSpeedMBs.Enabled = True

'My problem [I want to prevent the calculation if user has selected same option in combobox]
NumericUpDown2.Value = NumericUpDown2.Value / 1000

End If
Posted
Updated 17-Jul-16 18:37pm

1 solution

Dim bFLAG_KB,bFLAG_MB as boolean

If ComboBox2.SelectedItem = "KB/s" Then

NumericUpDown2.DecimalPlaces = 0
NumericUpDown2.Increment = 1
TranferRateSpeedKBs.Enabled = True
TranferRateSpeedMBs.Enabled = False

'My problem [I want to prevent the calculation if user has selected same option in combobox]
   if NOT bFLAG_KB then
      NumericUpDown2.Value = NumericUpDown2.Value * 1000
      bFLAG_KB =true
   End IF
ElseIf ComboBox2.SelectedItem = "MB/s" Then
NumericUpDown2.DecimalPlaces = 2
NumericUpDown2.Increment = 0.01
TranferRateSpeedKBs.Enabled = False
TranferRateSpeedMBs.Enabled = True

'My problem [I want to prevent the calculation if user has selected same option in combobox]
    If NOT bFLAG_MB THEN
       NumericUpDown2.Value = NumericUpDown2.Value / 1000
       bFLAG_MB = True
    END IF
End If
 
Share this answer
 
Comments
YusairiYap 18-Jul-16 6:27am    
First of all thanks J.O.V.Y. for helping me!
The problem still persists even after I try out your code. When user click the same item in combobox the calculation will repeat again. This is really troubling me.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900