How to add rows to gridview dynamically in windows phone?

How to add rows to gridview dynamically in windows phone 7.1 application?

  • in my window phone 7.1 application(silverlight application, c# language using VS 2010 express for windows phone) i created gridview to show my data(search results) in table format. I created a class and bound that gridview to that class succussfully. this is my xaml code: <phone:PhoneApplicationPage.Resources> <local:searchResultItemModel x:Key="searchResultIM"/> </phone:PhoneApplicationPage.Resources> <gridView:GridView x:Name="GridView1" CellSpacing="1" RowSpacing="1" SelectedItemChanged="GridViewSelectedItemChanged" Margin="26,16,25,22" ItemsSource="{Binding Source={StaticResource searchResultIM}, Path=Data}"> But i want to add rows dynamically. As this is static i cant able to add rows to it. Is anyother way to add rows dynamically. Could anybody help me please?

  • Answer:

    Building a DataGrid Control for Silverlight for Windows Phone http://www.silverlightshow.net/items/Building-a-DataGrid-Control-for-Silverlight-for-Windows-Phone-Part-1.aspx This suits the way to create a dynamic table perfectly, The problem in using list box is if the contents goes beyind windows phone, its not easy then to create table using listbox. This grid control has lot of features that would help a newbie like me. Its totally intuitive

user1099894 at Stack Overflow Visit the source

Was this solution helpful to you?

Other answers

You have to use the ListBox Control and template it to your liking. The ListBox also includes bunch of features like UIVitualization that will help with bigger sets of data.

Jasper

As said you can use the ListBox with a datatemplate to control the look of each row. Example: <ListBox ItemsSource="{Binding Source={StaticResource searchResultIM}, Path=Data}" ItemTemplate="{StaticResource SearchItemTemplate}" /> Put the above ListBox element inside your LayoutRoot (usually a Grid control) in your Phone page. In the ListBox you will refer to the ItemTemplate to use (defined as DataTemplate) which you define in your resources section, example: <DataTemplate x:Name="SearchItemTemplate"> <Grid> <Grid.ColumnDefinitions> <ColumnDefinition Width="Auto" /> <ColumnDefinition /> </Grid.ColumnDefinitions> <TextBlock Text="{Binding YourDataProperty1}" /> <TextBlock Text="{Binding YourDataProperty2}" Grid.Column="1" /> </Grid> </DataTemplate> The datacontext for the template will be the type of object you get in your results. So YourDataProperty1 etc could be a property on that resultobject. Hope it helps! /Anders

Netlight_Mobile

Related Q & A:

Just Added Q & A:

Find solution

For every problem there is a solution! Proved by Solucija.

  • Got an issue and looking for advice?

  • Ask Solucija to search every corner of the Web for help.

  • Get workable solutions and helpful tips in a moment.

Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.