Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6720911
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T09:16:05+00:00 2026-05-26T09:16:05+00:00

I am SIMPLY trying to set an ID Value (using ListBox.SelectedValuePath) to a WPF

  • 0

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):

    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;
    }

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.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T09:16:06+00:00Added an answer on May 26, 2026 at 9:16 am

    Allow me to explain a few of the things you are doing in your code, and the answer will be crystal clear.

    You are provided a list of “ListContent” objects to the listbox.

    lstBidPeriods.DisplayMemberPath = "Text";
    lstBidPeriods.ItemsSource = func.GetBidPeriods(....
    

    So, I assume that you have a public property in the ListContent class called “Text”. If so, then your list will show up, listing the ids of your BidPeriods. Great.

    But you also specified this:

    lstBidPeriods.SelectedValuePath = "Value";
    

    By doing that you change how the selection works a little bit. Lets take a look at the various selection properties.

    lstBidPeriods.SelectedItem – Returns the actual ListContent instance that is selected, because remember you passed a list of ListContent instances.

    lstBidPeriods.SelectedValue – Returns the “Value” property of the selected ListContent instance – so this is the date string

    lstBidPeriods.SelectedIndex – Returns the index of the selected item in the list.

    So to get the date string, use the SelectedValue,

    if (DateTime.TryParse(lstBidPeriods.SelectedValue.ToString(), out date))
    {
       ...
    }
    

    That’s it.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to set the value of a hidden property using the ViewBag
Using an example from MSDN I'm trying to set the value of a cell
I'm trying to set together a simple TextBox with some watermark text in the
I'm using Spring 3, and trying to set up a simple web-app using annotations
I'm trying to set up the following tables using JPA/Hibernate: User: userid - PK
I'm trying to find a tidy way to set a string using an if
OK, so I am trying to set up a simple JSF application. I'm using
I'm using the code: var x = function() {return true;}; trying to set x
I'm trying to set up a simple addition sequence using the random generator. The
My objective here is really simple -- I'm trying to set an NSString to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.