|
-
July 27th, 2011, 10:56 AM
#11
Re: button1_click help?
Please use code tags.
You have some Selected Index Changed handlers that you don't really need. Well as far as I can tell. It looks to me that the comboboxes are not dependant on one another - in other words, a dependant combobox's contents would change when as another combobox selection changed. This doesn't seem to be the case here.
If that is true then you can remove all the selected index changed handlers and just retrieve the selected indexes of the comboboxes the calculation button handler.
Code:
private void Calculate_Click(object sender, EventArgs e)
{
double subAmt = BevCost[ comboBox1.SelectedIndex ]
+ AppCost[ comboBox2.SelectedIndex ]
+ MainCost[ comboBox3.SelectedIndex ]
+ DesCost[ comboBox4.SelectedIndex ];
lblSubAmt.Text = subAmt.ToString();
double taxAmt= subAmt * 0.07;
lblTaxAmt.Text = taxAmt.ToString();
double totalAmt = subAmt + taxAmt;
lblTotalAmt.Text = totalAmt.ToString();
}
So in the code above, I've retrieved the selected indexes for the comboboxes and did the Cost array lookups inline. Also, you may have noticed that for naming the local variables, I've gone from PascalCase naming convention to a camelCase naming. In C#, camelCased naming is used for local and method parameter variables. So the local 'SubAmt' variable would be named 'subAmt', not 'SubAmt'.
Tags for this Thread
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
|