Reputation: 35
I have a Longliseselector in Xaml for windows phone 8
i'm populating it using a database
it works fine without grouping but when i group it it just shows a few empty lists
this code works
using (Database ctx = new Database(Database.ConnectionString))
{
ctx.CreateIfNotExists();
var tdr = from p in ctx.Transactions
join c in ctx.Type on p.Type equals c.Id
where p.Date > DateTime.Today.AddDays(-1 * ra) && c.Type1.Equals(ty)
select new { Id = p.Id, amont = p.Amont, type = c.Name, des = p.Des, dated = p.Date };
list21.ItemsSource = tdr.ToList();
}
But when i group it so i have jumplists it just does not work without any errors
using (Database ctx = new Database(Database.ConnectionString))
{
ctx.CreateIfNotExists();
var tdr = from ii in
(
from p in ctx.Transactions
join c in ctx.Type on p.Type equals c.Id
where p.Date > DateTime.Today.AddDays(-1 * ra) && c.Type1.Equals(ty)
select new { Id = p.Id, amont = p.Amont, type = c.Name, des = p.Des, dated = p.Date }
)
group ii by ii.Id;
list32.ItemsSource = tdr.ToList();
}
what am i doing wrong?
Upvotes: 1
Views: 70
Reputation: 191
http://msdn.microsoft.com/en-us/library/windows/apps/jj244365(v=vs.105).aspx
You have missed the KeyedList... Try:
{
ctx.CreateIfNotExists();
var tdr = from ii in
(
from p in ctx.Transactions
join c in ctx.Type on p.Type equals c.Id
where p.Date > DateTime.Today.AddDays(-1 * ra) && c.Type1.Equals(ty)
select new { Id = p.Id, amont = p.Amont, type = c.Name, des = p.Des, dated = p.Date }
)
group ii by ii.Id into iii select new KeyedList<string, COLLECTIONITEM>(iii);
list32.ItemsSource = new List<KeyedList<string, COLLECTIONITEM>>(tdr);
}
public class KeyedList<TKey, TItem> : List<TItem>
{
public TKey Key { protected set; get; }
public KeyedList(TKey key, IEnumerable<TItem> items)
: base(items)
{
Key = key;
}
public KeyedList(IGrouping<TKey, TItem> grouping)
: base(grouping)
{
Key = grouping.Key;
}
}
Don't forget this in the GroupHeaderTemplate:
<TextBlock Text="{Binding Key}" />
Upvotes: 1