Click here to Skip to main content
15,891,136 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
my table is look like this
1)Item_table:
id
list_name
category_name
item_name
price
qty
amount

i want to display it like this
category_name (count)

item1 qty price
item2 qty price

category_name (count)

item1 qty price
item2 qty price

till now i had tried listbox design:
HTML
<ListBox x:Name="listbox_all_items" Width="440">
                        <ListBox.ItemTemplate>
                            <DataTemplate>
                        <TextBlock Text="{Binding category_name}"></TextBlock>
                        <TextBlock Text="{Binding item_name}" FontSize="28"></TextBlock>
                        <TextBlock Text="{Binding qty}" FontSize="24"></TextBlock>

                                </Grid>
                            </DataTemplate>
                        </ListBox.ItemTemplate>
                    </ListBox>

C#
public void itemlist()
    {

    var query = from shoppingItem w in db.Item1
                    group w by new { w.category_name } into g
                    select new { category = g.Key.category_name, g };
    }

but how should I convert query variable to list so that i can bind it listbox.
Posted
Updated 7-Jun-12 9:07am
v2

I am a little confused by the quesiton, but I there is a very easy way to convert a LINQ query result to a list and that is to use the ToList() method.

The technolgy looks a lot like WPF or Silverlight. That means that you will have to set the ItemsSource for the ListBox to an IEnumerable of the class that contains the collection of objects with the properties category_name, item_name, and qty. This means that I am a little confused about the group by query. You don't need because you need tha category name. What I think you need is:

C#
var query = from shoppingItem in db.Items
                    select new { shoppingItem.category_name, 
                                 shoppingItem.item_name,
                                 shoppingItem.qty};


Pardon errors due to me not knowing everything about your problem.
 
Share this answer
 
You can get IEnumerable as a result of query expression.

You can directly assign this to itemsource of listbox.

For your requirement LongListSelector suits. Try Toolkit Longlistselector.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900