Note that there are some explanatory texts on larger screens.

plurals
  1. POSetting id value for a ListBoxItem in Windows Mobile 7
    primarykey
    data
    text
    <p>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:</p> <pre><code>public void display_Tips() { //commented out to try MrMDavidson's approach. // listBoxTipHistory.Items.Clear(); // IList&lt;Tips&gt; 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 &gt; 0) { listBoxTipHistory.Items.Clear(); } listBoxTipHistory.ItemsSource = get_Tips(); } public IList&lt;Tips&gt; get_Tips() { IList&lt;Tips&gt; tips = null; using (TipContext context = new TipContext(conString)) { IQueryable&lt;Tips&gt; query = (from c in context.TipTable orderby c.date descending select c); tips = query.ToList(); } return tips; } </code></pre> <p>Table for local database:</p> <pre><code>[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; } } </code></pre> <p>Xaml code:</p> <pre><code> &lt;ListBox SelectionChanged="showTipDetails" x:Name="listBoxTipHistory" Margin="6,3,0,0"&gt; &lt;DataTemplate&gt; &lt;StackPanel&gt; &lt;TextBlock Text="{Binding resturant}" /&gt; &lt;TextBlock Text="{Binding date}" /&gt; &lt;TextBlock Text="{Binding tip_amount}" /&gt; &lt;/StackPanel&gt; &lt;/DataTemplate&gt; &lt;/ListBox &gt; </code></pre> <p>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. </p> <p>Moreover, is there a special way to handle dates and time?</p> <p>Any suggestions would be appreciated.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload