Click here to Skip to main content
15,849,130 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
In the below code OTRate value does not get passed to the textbox1
private void
textBox1_TextChanged(object sender, EventArgs e)
        double OTRate = (double)(comboBox3.SelectedItem) * (int)(comboBox6.SelectedItem);

        textBox1.Text = OTRate.ToString();


What I have tried:

textBox1_TextChanged(object sender, EventArgs e)
double OTRate = (double)(comboBox3.SelectedItem) * (int)(comboBox6.SelectedItem);

textBox1.Text = OTRate.ToString();

Updated 18-Sep-16 0:49am
Richard MacCutchan 18-Sep-16 4:04am    
You need to use the debugger to find out whate each value is returning inside this method.
Karthik_Mahalingam 18-Sep-16 4:48am    
what value do you get in comboBox3.SelectedItem ?
Charvi Janathri 18-Sep-16 5:24am    
it is a value of real data type,user input
Karthik_Mahalingam 18-Sep-16 5:31am    
are you getting the correct value in that object
Charvi Janathri 18-Sep-16 5:53am    
yes I am I am getting values like 2500.00 for that combobox

does not get passed to the textbox1

Well... that's probably just as well, really.
Look at your code - and I'll rip out the irrelevant stuff - and it's pretty obvious you have a problem:
textBox1_TextChanged(object sender, EventArgs e)
    textBox1.Text = OTRate.ToString();
So...when Textbox1 changes, you set a new value for Textbox1. Which causes a changed event to occur, and that means you handle the event, which...changes Textbox1 again. And this repeats until everyone gets bored, or you kill the application.

I don't think you want to handle the TextChanged event to do this - and if you do, you certainly don't want to change the text within it!
Share this answer
Charvi Janathri 18-Sep-16 5:28am    
Then how can I show the result I get in textbox1?
OriginalGriff 18-Sep-16 5:30am    
Probably by not handling it's TextChanged event, but working with the ComboBox's events instead?
Charvi Janathri 18-Sep-16 5:52am    
okay then shall i use a button click to handle it and when i use the button click the value i get is always 0, I dont know why it does not give the calculated answer
OriginalGriff 18-Sep-16 6:02am    
Start change it slightly, and look at what you get with the debugger:
double d = (double)(comboBox3.SelectedItem);
int i = (int)(comboBox6.SelectedItem);
double OTRate = d * i;
Put a breakpoint on the last line of that, and use the debugger to look at the values in d and i.
We can't do that for you - we don't have access to the comboboxes!

Charvi Janathri 18-Sep-16 6:08am    
the problem is i dont know how to debug but now i am learning it Thanku so much for your help I ll do what u said :) Thanks!
You should learn to use the debugger as soon as possible. Rather than guessing what your code is doing, It is time to see your code executing and ensuring that it does what you expect.

The debugger allow you to follow the execution line by line, inspect variables and you will see that there is a point where it stop doing what you expect.
Debugger - Wikipedia, the free encyclopedia[^]
Mastering Debugging in Visual Studio 2010 - A Beginner's Guide[^]

The debugger is here to show you what your code is doing and your task is to compare with what it should do.
When the code don't do what is expected, you are close to a bug.
Share this answer
Charvi Janathri 18-Sep-16 5:51am    
Thankyou so much I ll use the debugger :)

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