title: How to get WPF ListBox Text displayed in the ListBox Window?
body: <p>I am SIMPLY trying to set an ID Value (using ListBox.SelectedValuePath) to a WPF ListBox and show the assoicated (Date) Text (using ListBox.DisplayMemberPath) in the ListBox Window. The problem is I am unable to GET the Text from the ListBox Window! I have done this numerous times using a ComboBox, but it does not seem to work with a ListBox. The ListBox does not have a ListBox.Text property from which to obtain the Text displayed in the ListBox Window, in this case a date.  Here is my code (I am trying to get the Text from the lstBidPeriods Window to populate a second ListBox (lstHolidays) by querying the database for holidays for the date of the selected bid period, from the lstBidPeriods):</p>
  
  <pre><code>    private void loadBidPeriods()
      {
          lstBidPeriods.DisplayMemberPath = "Text";
          lstBidPeriods.SelectedValuePath = "Value";
          //lstBidPeriods.ItemTemplate.RegisterName(
          lstBidPeriods.ItemsSource = func.GetBidPeriods(func.SelectedYear, func.SelectedMonth);
      }
      private void lstBidPeriods_SelectionChanged(object sender, SelectionChangedEventArgs e)
      {
          lstHolidays.ItemsSource = null;
          DateTime date = DateConversions.MIN_DATE;
          Console.WriteLine("SelectedItem= " + lstBidPeriods.SelectedItem.ToString());
          Console.WriteLine("SelectedValue= " + lstBidPeriods.SelectedValue.ToString());
          Console.WriteLine("Items[index]= " + lstBidPeriods.Items[lstBidPeriods.SelectedIndex].ToString());
          if (DateTime.TryParse(lstBidPeriods.SelectedItem.ToString(), out date))
          {
              Console.WriteLine("BID date: " + date);
              lstHolidays.DisplayMemberPath = "Text";
              lstHolidays.SelectedValuePath = "Value";
              lstHolidays.ItemsSource = func.GetBidPeriodHolidays(date);
          }
          Console.WriteLine("NOW date: " + date);
      }
  
     public ArrayList GetBidPeriods(short selYear, byte selMonth)
      {
          DataTable periods = new DataTable();
          ArrayList list = new ArrayList();
          try
          {
              SqlConnection conn = openNewConnection();
              SqlCommand cmd = new SqlCommand("getBidPeriods", conn);
              cmd.CommandType = CommandType.StoredProcedure;
              cmd.Parameters.Add("@selMonth", SqlDbType.TinyInt);
              cmd.Parameters.Add("@selYear", SqlDbType.SmallInt);
              cmd.Parameters["@selMonth"].Value = selMonth;
              cmd.Parameters["@selYear"].Value = selYear;
              periods = GetDataTable(cmd);
              foreach (DataRow row in periods.Rows)
              {
                  DateTime date = new DateTime((short)row["Bid_Year"], (byte)row["Bid_Month"], (byte)row["Bid_Day"]);
                  list.Add(new ListContent(row["Bid_Id"].ToString(), date.ToShortDateString()));
              } 
              conn.Close(); conn.Dispose(); cmd.Dispose();
          }
          catch (Exception e)
          {
              message = "Error Obtaining Bid Periods: " + e.Message.ToString();
              FileWizard.writeDate(FileWizard.LOGFILE_DIRECTORY + "appExceptionLog_"
                  + DateConversions.GetMonthName(now.Month) + now.Year.ToString() + ".log",
                  "User: " + GFIFunctions.GFIUser + "\tClass: GFIDBInterface\tFunction: GetBidPeriods"
                  + "\tException: " + message);
              MessageBox.Show("Notify System Administrator: " + message, "GFI RIDER Application Exception ");
          }
          return list;
      }
      public ArrayList GetBidPeriodHolidays(DateTime bidPeriodDateStartingWithDate)
      {
          DataTable holidays = new DataTable();
          ArrayList list = new ArrayList();
          try
          {
              SqlConnection conn = openNewConnection();
              SqlCommand cmd = new SqlCommand("getBidPeriodHolidays", conn);
              cmd.CommandType = CommandType.StoredProcedure;
              cmd.Parameters.Add("@bidHolidayDatesGreaterThanOrEqualTo", SqlDbType.DateTime);
              cmd.Parameters["@bidHolidayDatesGreaterThanOrEqualTo"].Value = bidPeriodDateStartingWithDate;
              holidays = GetDataTable(cmd);
              foreach (DataRow row in holidays.Rows)
              {
                  list.Add(new ListContent(row["Bid_Holiday_Id"].ToString(), ((DateTime)row["Bid_Holiday_Date"]).ToShortDateString()));
              } 
              conn.Close(); conn.Dispose(); cmd.Dispose();
          }
          catch (Exception e)
          {
              message = "Error Obtaining Bid Period Holidays: " + e.Message.ToString();
              FileWizard.writeDate(FileWizard.LOGFILE_DIRECTORY + "appExceptionLog_"
                  + DateConversions.GetMonthName(now.Month) + now.Year.ToString() + ".log",
                  "User: " + GFIFunctions.GFIUser + "\tClass: GFIDBInterface\tFunction: GetBidPeriodHolidays"
                  + "\tException: " + message);
              MessageBox.Show("Notify System Administrator: " + message, "GFI RIDER Application Exception ");
          }
          return list;
      }
  </code></pre>
  
  <p>PLEASE:  I do not need to BIND anything, so don't go there.  This SHOULD be a SIMPLE procedure, not anything complicated with UNECESSARY binding.</p>