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
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:
- How to add empty rows to the JQGrid?Best solution by Stack Overflow
- How to do HttpWebRequests from a Windows Phone 7?Best solution by stackoverflow.com
- How to add new row to a databound gridview?Best solution by Stack Overflow
- I have a phone with Windows Mobile 6.1 and can't sync with yahoo.Best solution by Yahoo! Answers
- How to Add a Yahoo Email Address to Windows Mail?Best solution by Yahoo! Answers
Just Added Q & A:
- How many active mobile subscribers are there in China?Best solution by Quora
- How to find the right vacation?Best solution by bookit.com
- How To Make Your Own Primer?Best solution by thekrazycouponlady.com
- How do you get the domain & range?Best solution by ChaCha
- How do you open pop up blockers?Best solution by Yahoo! Answers
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.