Click here to Skip to main content
15,921,941 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
Here, user will enter employee Id, Name and Salary information in the related textboxes and press “Keep it”. When user press “Keep it” button employee data will be saved to the next Combobox.

So, if user enters three employees information, three employees’ name will be added in the drop down list of Combobox.

After entering several employees’ information, user will select a particular employee from the drop down list of Combobox and press “Show” button, all information (Id, Name, Salary) of the selected employee will be displayed in the messagebox as following format:

Employee Information:
Id:001
name:alman
Salary:1000

C#
namespace WindowsApplicationPraticeOne
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }
        private string id;
        private string name;
        private double salary;
        private void keepItbutton_Click(object sender, EventArgs e)
        {
             id = idtextBox.Text;
             name = nametextBox.Text;
             salary =Convert.ToDouble(salarytextBox.Text);
             employecomboBox.Items.Add(name);
       }
        private void showbutton_Click(object sender, EventArgs e)
        {
        }
    }
}
Posted
Updated 5-Mar-11 18:43pm
v3
Comments
Sandeep Mewara 6-Mar-11 0:44am    
Not clear on where are you stuck and what is the question here.
alman hossain 6-Mar-11 0:46am    
i can just display the items in the combobox. but i can't show the selected items information.how can i save the data in combobox and display the data .please help anyone .. i am beginner and cant find a way
alman hossain 6-Mar-11 0:52am    
i can not save the data in combo box . i want to display all the data of selected item in combo box like id, name , salary etc
alman hossain 6-Mar-11 0:56am    
please help... i stuck on saving and displaying data in combobox
m@dhu 6-Mar-11 1:03am    
Don't reply to your own comment. Reply to Sandeep's comment.

make a class Employee like this
class Employee
{
  public string Id;
  public string Name;
  public double Salary; 
}


now take a hash table
HashTable hsEmp=new HashTable();


now change your code as
private void keepItbutton_Click(object sender, EventArgs e)
       {
            Empolyee objEmp=new Employee();
            objEmp.id = idtextBox.Text;
            objEmp.name = nametextBox.Text;
            objEmp.salary =Convert.ToDouble(salarytextBox.Text);
            hsEmp.Add(objEmp.Name,objEmp);
            employecomboBox.Items.Add(name);
      }
       private void showbutton_Click(object sender, EventArgs e)
       {
           Employee objEmp=hsEmp[cboEmp.SelectedValue];
// write code to show employee data;

       }



--Pankaj
 
Share this answer
 
Class Emp
{
   string id;
   string name;
   doubl sal;
}

namespace WindowsApplicationPraticeOne
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }
        IDictionary empDic<string,emp> = new Dictionary<string,emp>();
        private void keepItbutton_Click(object sender, EventArgs e)
        {
             Emp temp=new Emp()
             temp.id = idtextBox.Text;
             temp.name = nametextBox.Text;
             temp.salary =Convert.ToDouble(salarytextBox.Text);
             employecomboBox.Items.Add(temp.name);
             empDic.add(temp.id,temp);
       }
        private void showbutton_Click(object sender, EventArgs e)
        {
             Emp temp2 = empDic[employecomboBox.SelectedText.toString()];
//Now you have you can use temp2 class to display data
        }
    }
}


P.S. : I have not compiled and tested the code but should work
 
Share this answer
 
private void buttonKeepIt_Click(object sender, EventArgs e)
{
   comboxEmpList.Add.Items(textBoxName.Text);
   //If you are using the database as MySql then use this query to store
   //MySql code: insert into Emptable(id,name,salary) values("18","YYY","28487.87");

}

private void buttonShow_Click(object sender, EventArgs e)
{
    string selectedEmpName = comboboxEmpList.Text;
    //If you are using the database as MySql then use this query to store
    //MySql code: slect * from Emptable where name = selectedEmpName;
    //Use MySql Adapter to get datatable or dataset
     
    textBoxName.Text = dataTable.Rows[0]["name"].ToString();
    textBoxid.Text = dataTable.Rows[0]["id"].ToString(); 
    textBoxSalary.Text = dataTable.Rows[0]["salary"].ToString();
   
}
 
Share this answer
 

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