By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
449,034 Members | 1,012 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 449,034 IT Pros & Developers. It's quick & easy.

Adding utility class array to a combo box and Displaying the values to TextBoxes

P: 1
Hi all I'm having a bit of trouble completeing my coursework basically so far i have created Citenary class with support methods for a private array. The problem is i can add objects to the array through a instance of the class in the main form but im having trouble retreving the data from a combobox. I have the values Name, Passport Number, Issuedby and Expires that are added to the array. The value name is passed to the combobox when a passanger is added but i cant retrive the data from the array for this passanger to display in the textboxes. Ive tryed using selected index changes events but it doesnt seem 2 work. Any help would be much appriciated.

Expand|Select|Wrap|Line Numbers
  1.   [Serializable()]
  2.     public class CItinerary
  3.     {
  4.         private ArrayList arrPassengers; //collection of CPassenger objects
  5.         private ArrayList arrDestinations; //collection of CDestinaton objects
  6.  
  7. #region "Passenger methods"
  8.         public void AddPassenger(CPassenger pIn)
  9.         {
  10.             arrPassengers.Add(pIn);
  11.         }
  12.         public void RemovePassenger(CPassenger pIn)
  13.         {
  14.             arrPassengers.Remove(pIn);
  15.         }
  16.         public void ClearPassanger()
  17.         {
  18.             arrPassengers.Clear();
  19.         }
  20. #region "Class CPassenger"
  21.     public class CPassenger
  22.     {
  23.         private string strName;
  24.         private long lPassportNo;
  25.         private string strIssuer;
  26.         private string strExpires;
  27.  
  28.         public CPassenger()
  29.         {
  30.             strName="Empty";
  31.             lPassportNo=-1;
  32.             strIssuer="Empty";
  33.             strExpires="01.01.1900";
  34.         }
  35.         public CPassenger(string nameIn, long passNoIn, string issuerIn, string expIn)
  36.         {
  37.             strName=nameIn;
  38.             lPassportNo=passNoIn;
  39.             strIssuer=issuerIn;
  40.             strExpires=expIn;
  41.         }
  42.         public string Name
  43.         {
  44.             get{return strName;}
  45.             set{strName = value;}
  46.         }
  47.         public long PassportNumber
  48.         {
  49.             get{return lPassportNo;}
  50.             set{lPassportNo = value;}
  51.         }
  52.         public string IssuedBy
  53.         {
  54.             get{return strIssuer;}
  55.             set{strIssuer = value;}
  56.         }
  57.         public string Expires
  58.         {
  59.             get{return strExpires;}
  60.             set{strExpires = value;}
  61.         }
  62.     }
  63.     #endregion 
  64.  
  65.  
  66.  
  67.  
  68.  
  69.  
  70. CItinerary objCurrItinerary; // the current itinerary object
  71.  private string strFileName;
  72. private bool bDirty; //controls save mode and display of cost calculatio
  73. #region "Constructors and Destructors"
  74. public frmPMFMain()
  75. {
  76. InitializeComponent();
  77. objCurrItinerary = new CItinerary(); //empty instance
  78. strFileName = "";
  79. bDirty = false;
  80. int intNumber = 0;
  81.  
  82.  
  83.  
  84.  
  85. ///*** Custom methods and events follow ***///
  86.         #region "Passengers"
  87.         public void AddPassanger()//add new passanger
  88.         {
  89.             CPassenger p = new CPassenger();
  90.             {
  91.                 p.Name = txtName.Text;
  92.                 String pNumber = txtPassport.Text;
  93.                 int intNumber = System.Convert.ToInt32(pNumber);
  94.                 p.PassportNumber = intNumber;
  95.                 p.IssuedBy = txtIssuer.Text;
  96.                 p.Expires = txtExpires.Text;
  97.                 objCurrItinerary.AddPassenger(p);
  98.                 cboPassList.Items.Add(p.Name);
  99.  
  100.                 MessageBox.Show("Passanger " + p.Name + " Has been Added");
  101.                 bDirty= true;   
  102.                 Invalidate();
  103.             }
  104.         }



Thanks matt
Mar 24 '07 #1
Share this question for a faster answer!
Share on Google+

Post your reply

Sign in to post your reply or Sign up for a free account.