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

  • Home
  • SEARCH
  • 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 7984909
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T11:25:09+00:00 2026-06-04T11:25:09+00:00

I’m trying to create a single select listbox from Linq, however, I’m running into

  • 0

I’m trying to create a single select listbox from Linq, however, I’m running into problems setting the id value of each listbox item with the corresponding id as saved in a local database. I have the following code:

public void display_Tips()
    {
       //commented out to try MrMDavidson's approach.
       // listBoxTipHistory.Items.Clear();
       // IList<Tips> tips = this.get_Tips();
       // foreach (Tips tip in tips)
       // {
       //     ListBoxItem li1 = new ListBoxItem();
       //     li1.Content = tip.date.Day + "-" + tip.date.Month + "-" + 
       //                       tip.date.Year + "-" + tip.date.Hour + ":" +
       //                       tip.date.Minute + " - " + tip.resturant + " - $" +
       //                       tip.tip_amount + " - $" + tip.billTotal;
       //     listBoxTipHistory.Items.Add(li1);
       // }
        if (listBoxTipHistory.Items.Count > 0)
        {
            listBoxTipHistory.Items.Clear();
        }
        listBoxTipHistory.ItemsSource = get_Tips();
}

public IList<Tips> get_Tips()
    {
        IList<Tips> tips = null;
        using (TipContext context = new TipContext(conString))
        {
            IQueryable<Tips> query =
                (from c in context.TipTable
                 orderby c.date descending
                 select c);
            tips = query.ToList();
        }
        return tips;
    }

Table for local database:

[Table]
public class Tips
{
    [Column(IsPrimaryKey = true, IsDbGenerated = true)]
    public int tip_ID
    {
        get;
        set;
    }
    [Column(CanBeNull = false)]
    public float tip_amount
    {
        get;
        set;
    }
    [Column]
    public string resturant
    {
        get;
        set;
    }
    [Column(CanBeNull = false)]
    public DateTime date
    {
        get;
        set;
    }
  }

Xaml code:

  <ListBox SelectionChanged="showTipDetails" x:Name="listBoxTipHistory" Margin="6,3,0,0">
                    <DataTemplate>
                      <StackPanel>
                        <TextBlock Text="{Binding resturant}" />
                        <TextBlock Text="{Binding date}" />
                        <TextBlock Text="{Binding tip_amount}" />
                      </StackPanel>
                    </DataTemplate>
                </ListBox >

I’m now trying to recode to work with MrMDavidson’s suggestion, however, with this current code it results in the list showing “AppName.Tips” rather than the actual column data. I’ve tried googling walkthroughs and tutorials on this, however, I’ve been unable to come up with a solution.

Moreover, is there a special way to handle dates and time?

Any suggestions would be appreciated.

  • 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-06-04T11:25:11+00:00Added an answer on June 4, 2026 at 11:25 am

    It sounds like you’re trying to do this from a WinForms / CF.Net style approach. Whilst you can probably do this I’d recommend against it as you’re really not getting the value of Silverlight. Let’s presume that your Tips class looks something like;

    public class Tip {
      public int Id { get; set; }
      public string Title { get; set; }
      public string Restaurant { get; set; }
    }
    

    You can then bind a list of these to a ListBox;

    listBoxTipHistory.ItemsSource = get_Tips()
    

    Your XAML is used to describe how these items are displayed;

    <ListBox x:Name="listBoxTipHistory">
      <ListBox.ItemTemplate>
        <DataTemplate>
          <StackPanel>
            <TextBlock Text="{Binding Title}" />
            <TextBlock Text="{Binding Restaurant}" />
          </StackPanel>
        </DataTemplate>
      </ListBox.ItemTemplate>
    </ListBox>
    

    The SelectedItem on the ListBox will be the currently selected Tip (as an object), not the actual ListBoxItem that’s selected. So to get the ID of the selected Tip;

    Tip selectedTip = listBoxTipHistory.SelectedItem as Tip;
    if (selectedTip != null) {
      Console.WriteLine("The selected Tip is {0}", selectedTip.Id);
    }
    

    A further suggestion would be for you to look into the INotifyPropertyChanged interface which will allow changes to your model to automatically get updated in the UI

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

Sidebar

Related Questions

Basically, what I'm trying to create is a page of div tags, each has
I am currently running into a problem where an element is coming back from
I'm trying to create an if statement in PHP that prevents a single post
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have a French site that I want to parse, but am running into
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I'm trying to use string.replace('’','') to replace the dreaded weird single-quote character: ’ (aka
I am trying to understand how to use SyndicationItem to display feed which is
For some reason, after submitting a string like this Jack’s Spindle from a text
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function

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.