title: display information about an object selected in a listbox in textboxes
body: <p>I want to display the information about whichever flight is selected in the listbox in textboxes next to it. My problem is I can't get my curFlight variable to work right gives me InvalidCastException was unhandled error and says When casting froim a number, the value must be a number less than infinity.</p>
  
  <p>heres my form code</p>
  
  <pre><code>using System;
  using System.Collections.Generic;
  using System.ComponentModel;
  using System.Data;
  using System.Drawing;
  using System.Linq;
  using System.Text;
  using System.Windows.Forms;
  
  namespace Reservations
  {
      public partial class Form1 : Form
      {
          public Form1()
          {
              InitializeComponent();
          }
  
          Flight curFlight;
  
          Flight flight1 = new Flight("Cessna Citation X", "10:00AM", "Denver", 6, 2);
          Flight flight2 = new Flight("Piper Mirage", "10:00PM", "Kansas City", 3, 2);
  
          private void Form1_Load(object sender, EventArgs e)
          {
              MakeReservations();
              DisplayFlights();
  
          }
  
          private void lstFlights_SelectedIndexChanged(object sender, EventArgs e)
          {
              curFlight = (Flight)lstFlights.SelectedItem;
              txtDepart.Text = curFlight.DepartureTime;
              txtDestination.Text = curFlight.Destination;
          }
  
          private void MakeReservations()
          {
              flight1.MakeReservation("Dill", 12);
              flight1.MakeReservation("Deenda", 3);
              flight1.MakeReservation("Schmanda", 11);
              flight2.MakeReservation("Dill", 4);
              flight2.MakeReservation("Deenda", 2);
          }
  
          private void DisplayFlights()
          {
              lstFlights.Items.Clear();
              lstFlights.Items.Add(flight1.Plane);
              lstFlights.Items.Add(flight2.Plane);
          }
  
          private void btnMakeReservation_Click(object sender, EventArgs e)
          {
              string name;
              int seatNum;
  
              name = txtCustomerName.Text;
              seatNum = Convert.ToInt16(txtSeatNum.Text);
  
              curFlight.MakeReservation(name, seatNum);
          }
      }
  }
  </code></pre>
  
  <p>HERES THE CLASS CODE</p>
  
  <pre><code> using System;
  using System.Collections.Generic;
  using System.Linq;
  using System.Text;
  
  namespace Reservations
  {
      class Flight
      {
          private string mPlane;
          private string mDepartureTime;
          private string mDestination;
          private int mRows;
          private int mSeats;
          private string[] mSeatChart;
  
          public Flight()
          {
          }
  
          public Flight(string planeType, string departureTime, string destination, int numRows, int numSeatsPerRow)
          {
              this.Plane = planeType;
              this.DepartureTime = departureTime;
              this.Destination = destination;
              this.Rows = numRows;
              this.Seats = numSeatsPerRow;
  
              // create the seat chart array
              mSeatChart = new string[Rows * Seats];
  
              for (int seat = 0; seat &lt;= mSeatChart.GetUpperBound(0); seat++)
              {
                  mSeatChart[seat] = "Open";
              }
          }
  
          public string Plane
          {
              get { return mPlane; }
              set { mPlane = value; }
          }
  
          public string DepartureTime
          {
              get { return mDepartureTime; }
              set { mDepartureTime = value; }
          }
  
          public string Destination
          {
              get { return mDestination; }
              set { mDestination = value; }
          }
  
          public int Rows
          {
              get { return mRows; }
              set { mRows = value; }
          }
  
          public int Seats
          {
              get { return mSeats; }
              set { mSeats = value; }
          }
  
          public string[] SeatChart
          {
              get { return mSeatChart; }
              set { mSeatChart = value; }
          }
  
  
          public void MakeReservation(string name, int seat)
          {
              if (seat &lt;= (Rows * Seats) &amp;&amp; mSeatChart[seat - 1] == "Open")
              {
                  mSeatChart[seat - 1] = name;
              }
              else
              {
                  //let calling program know it didnt work.
  
              }
          }
  
          public bool IsFull()
          {
              return false;
          }
      }
  }
  </code></pre>