Click here to Skip to main content
15,897,187 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
plz help me in code for calculating rate automatically when user select an item from first combobox and travelling time from second combobox and weight from third combobox for my cargo desktop application.kindly plz help me
Posted
Comments
[no name] 9-Sep-11 15:29pm    
This depends on your business rules. Are you asking us to define some business rules for you??
This has little to do with programming.... Or are you having troubles accessing items for your business logic?

You will need to add code that will execute on the SelectedIndexChanged event of each combo;
(Example below is a form with 2 combobox, drop down list style, and a label, and is basically your basic times table multiplier
e.g.
C#
public partial class Form1 : Form
{
    public Form1()
    {
        InitializeComponent();
    }

    private void Form1_Load(object sender, EventArgs e)
    {
        //Add integers 0 to 10 (inc) to the combo box lists
        for (int x = 0; x < 11; x++)
        {
            comboIP1.Items.Add(x.ToString());
            comboIP2.Items.Add(x.ToString());
        }
    }


    //Attached to the SelectedIndexChanged of both ComboBox
    private void calcResult(object sender, EventArgs e)
    {
        try
            {
                int input1 = int.Parse(comboIP1.SelectedItem.ToString());
                int input2 = int.Parse(comboIP2.SelectedItem.ToString());
                int result = input1 * input2;
                labelResult.Text = result.ToString();
            }
        catch (Exception ex)
            {
                labelResult.Text = "0";

            }
    }
}
 
Share this answer
 
Please explain more about your question.
what is the type of first item? and what's the format of time? its in the hh:mm:ss format or in long datetime format? or its just an int that show the time period like : t3=t2-t1.
but for a hint if u have textbox named txtRate (for showing the result) and 2 combobox (cmbItem and cmbTime) u can use this:
C#
public partial class Form1 : Form
{
     public Form1()
     {
          InitializeComponent();
	  cmbItem.SelectedIndexChanged += comboBoxs_SelectedIndexChanged;
	  cmbTime.SelectedIndexChanged += comboBoxs_SelectedIndexChanged;
     }
 
     private void comboBoxs_SelectedIndexChanged(object sender, EventArgs e)
     {
	  try
	  {
	       double item = (double)cmbItem.SelectedItem;
	       double timeperiod = (double)cmbTime.SelectedItem;
	       double rate = item / timeperiod;
	       txtRate.Text = rate.ToString();
	  }
	  catch (Exception ex)
	  {
	       // do some appropriate actions
	  }
     }
}
 
Share this answer
 
v2

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