5 Replies - 722 Views - Last Post: 04 June 2009 - 10:12 PM Rate Topic: -----

#1 smallzz  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 04-June 09

Storing information about one person in a combobox

Posted 04 June 2009 - 01:21 PM

well im very in experienced at C# and i have an assignment to do from college on it. the program is about inserting how many hours a person has worked and the rate of pay for each hour, it then has to calculate tax etc. etc. I have got all of the sums and calculations correct and working the problem is that i want it to store the information entered into the system about 1 person within a list of people within a combobox. all though i have looked around i cannot find anything that seems to work... can anyone suggest an idea? thanks in advance

John

p.s. when i choose the perons ID on the input form after that no matter who i choose the same pay details come up

This post has been edited by smallzz: 04 June 2009 - 01:22 PM


Is This A Good Question/Topic? 0
  • +

Replies To: Storing information about one person in a combobox

#2 eclipsed4utoo  Icon User is offline

  • Not Your Ordinary Programmer
  • member icon

Reputation: 1524
  • View blog
  • Posts: 5,957
  • Joined: 21-March 08

Re: Storing information about one person in a combobox

Posted 04 June 2009 - 01:56 PM

where do you want to store the information? Text file? Database?
Was This Post Helpful? 0
  • +
  • -

#3 smallzz  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 04-June 09

Re: Storing information about one person in a combobox

Posted 04 June 2009 - 02:18 PM

i have already stored it in a textfile but i need to be able to just take one bit of information out and put it into a textbox on the last page which will be a summary page of all the employees names and net pay
Was This Post Helpful? 0
  • +
  • -

#4 masteryee  Icon User is offline

  • D.I.C Regular

Reputation: 40
  • View blog
  • Posts: 271
  • Joined: 16-May 09

Re: Storing information about one person in a combobox

Posted 04 June 2009 - 02:35 PM

Create your own item class to add to your combobox:

http://tipsntricksbd...common-gui.html
Was This Post Helpful? 0
  • +
  • -

#5 smallzz  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 04-June 09

Re: Storing information about one person in a combobox

Posted 04 June 2009 - 02:46 PM

		private void cbxID_SelectedIndexChanged(object sender, EventArgs e)
		{//shows name in txtName afte you pick a user ID from combo box

			if (cbxID.SelectedIndex == 001)
				txtName.Text = "John Smith";
			else if
				(cbxID.SelectedIndex == 002)
				txtName.Text = "Michael Alderwood";
			else if
				(cbxID.SelectedIndex == 003)
				txtName.Text = "Thomas Hooper";
			else if
				(cbxID.SelectedIndex == 004)
				txtName.Text = "Nathan Church";
			else if
				(cbxID.SelectedIndex == 005)
				txtName.Text = "Jonas Gutierrez";
			else if
				(cbxID.SelectedIndex == 006)
				txtName.Text = "James Jackson";
			else if
				(cbxID.SelectedIndex == 007)
				txtName.Text = "Jake McNally";
			else if
				(cbxID.SelectedIndex == 008)
				txtName.Text = "Stacey Jameson";
			else if
				(cbxID.SelectedIndex == 009)
				txtName.Text = "Jet Li";
			else if
				(cbxID.SelectedIndex == 010)
				txtName.Text = "Alan Sheffield";

		}



that is my combo box so for which i just want to assign information to what is selected so on the next form when i select that person the pay details show up instead of the last pay details entered showing up for everyone.
thanks
Was This Post Helpful? 0
  • +
  • -

#6 masteryee  Icon User is offline

  • D.I.C Regular

Reputation: 40
  • View blog
  • Posts: 271
  • Joined: 16-May 09

Re: Storing information about one person in a combobox

Posted 04 June 2009 - 10:12 PM

You're probably not storing the individual employee data in memory, so that's why you're only seeing the most recently entered data. Hmm, you can try something like this (sorry if it doesn't compile...I'm manually typing it and it requires .NET 3.0 because of the Automatic Properties:

   public class Employee
   {
      public string Name {get; set;}
      public double HoursWorked {get; set;}
      public double PayRate {get; set;}

      public Employee(string name)
      {
         Name = name;
      }

      public override string ToString()
      {
         return Name;
      }
   }

   ....in your main code, load the employees prior to your form loads
   cbxID.Items.Add(new Employee("John Smith"));
   cbxID.Items.Add(new Employee("Michael Alderwood"));
   ....
   ....load the same objects into your second comboBox
   foreach (Employee e in cbxID.Items)
      comboBox2.Items.Add(e);

   ... when you select a name from your first combo box:
   Employee e = (Employee)cbxID.SelectedItem;
   ... when you want to apply changes to the hours and pay rate
   e.HoursWorked = Convert.ToDouble(hoursTextBox.Text);
   e.PayRate = Convert.ToDouble(payTextBox.Text);

   ...do something similar when you need to access the data in the second combo box
   Employee e = (Employee)comboBox2.SelectedItem;
   displayHoursTextBox.Text = e.HoursWorked.ToString();
   displayPayRateTextBox.Text = e.PayRate.ToString();
   displayTotalTextBox.Text = (e.PayRate*e.HoursWorked).ToString();



Does this help at all?
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1