i am binding data to listbox in wp7
here is the code
<ListBox x:Name="list_budget" Width="440">
<ListBox.ItemTemplate>
<DataTemplate>
<TextBlock Name="txtname" Text="{Binding category}"></TextBlock>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
//class function
public string[] jinal;
public void budgetcategorywise()
{
var q = from shoppingItem p in db.Item1
group p by new { p.category_name } into g
select new { category = g.Key, total = g.Sum(p => p.total_amt) `enter code here`}.ToString();
jinal = q.toarray();
}
//coding
list_budget.ItemsSource = App.Viewmod.jinal;
now,the error is query is ok result is perfact but i am not able to bind the data to listbox.
Looking at your code sample:
budgetcategorywise()is called before you do the bindingPlease change your binding to:
The reason for this second change is that your code uses a
ToString()in the Linq list generation – which means that the class with itscategoryfield is flattened in a string represenation.If you wish to keep the category field in your binding then use a class for your list items like: