locked
Grid View show data RRS feed

  • Question

  • hello, 

    I don't show data in my gridview using sqlite.

    The items work but not show data in 'NomeCurso'

    my code xaml:

                                

         <!-- Horizontal scrolling grid used in most view states -->
            <GridView

                x:Name="itemGridView"
                AutomationProperties.AutomationId="ItemsGridView"
                AutomationProperties.Name="Items"
                TabIndex="1"
                Grid.RowSpan="2"
                Padding="116,136,116,46"
                ItemsSource="{Binding Source={StaticResource itemsViewSource}}"
                ItemTemplate="{StaticResource Standard250x250ItemTemplate}"
                SelectionMode="None"
                IsSwipeEnabled="false"
                ItemClick="Event_Page" 
                IsItemClickEnabled="True"
                >


                    <Grid>
                        <TextBlock  Text="{Binding NomeCurso}" ></TextBlock>
                    </Grid> </GridView>

    and my column in table Curso is NomeCurso. Thanks

    Monday, October 7, 2013 2:18 PM

Answers

  • try this

    <ScrollViewer VerticalScrollBarVisibility="Disabled" Grid.Column="1" HorizontalScrollBarVisibility="Auto" ZoomMode="Disabled"  >
                    <GridView Name="itemListViewss" IsRightTapEnabled="False"  ItemsSource="{Binding}" AllowDrop="True" ItemClick="itemListViewss_ItemClick" HorizontalAlignment="Center" VerticalAlignment="Top" IsItemClickEnabled="True" Margin="15,0,0,0" Height="140" Tag="0">
                    <GridView.ItemTemplate>
                        <DataTemplate>                       
                                <Grid HorizontalAlignment="Left" Height="140" Width="170" VerticalAlignment="Top" >
                                    <Image Margin="0" Source="{Binding Path=templateName}" Stretch="Fill" Width="170" Height="140" x:Name="imagegrid" PointerExited="Grid_PointerExited"/>
                                    <Grid HorizontalAlignment="Left" Height="68" Margin="0" VerticalAlignment="Bottom" Width="170" Background="#E5231F20" >
                                        <TextBlock HorizontalAlignment="Center" Foreground="White" TextWrapping="Wrap" Text="{Binding reportName}" VerticalAlignment="Center" FontSize="14" Tag="{Binding procedureName}" Margin="0,-15,0,0" PointerEntered="Grid_PointerEntered" PointerExited="Grid_PointerExited" />
                                        </Grid> 
                                </Grid>                      
                        </DataTemplate>
                    </GridView.ItemTemplate>
                </GridView>
                </ScrollViewer>

    first inside datatemplate copy code and put in sample test page inthere do static instead of binding give some text and try then put inside gridview

    • Marked as answer by Aurelien Mota Tuesday, October 8, 2013 2:24 PM
    Tuesday, October 8, 2013 1:56 PM

All replies

  • Hi Aurelien,

    I'm not quite sure what you mean by here, if you don't mind explain it in detail, for instance "The items work but not show data in 'NomeCurso'" means items can be shown but textblock cannot display? or you could upload your demo to skydrive we can help to analysis the code.

    But I do think your issue might be "how to handling the binding for GirdView", therefore I'd like suggest a tutorial for you: Adding ListView and GridView controls.

    Besides some samples are also available:

    Best Regards,

    --James


    <THE CONTENT IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, WHETHER EXPRESS OR IMPLIED>
    Thanks
    MSDN Community Support

    Please remember to "Mark as Answer" the responses that resolved your issue. It is a common way to recognize those who have helped you, and makes it easier for other visitors to find the resolution later.


    Tuesday, October 8, 2013 1:43 AM
    Moderator
  • thanks Jamles, 

    this is it works in image:

    but does not show the textblock (Text) in each item where in this database.

    thanks you

    Tuesday, October 8, 2013 11:26 AM
  • Do you implement INotifyPropertyChanged interface?

    Please, provide full code behind with methods where you set data and properties.

    Tuesday, October 8, 2013 12:49 PM
  • My code XAML:

    <common:LayoutAwarePage
        x:Name="pageRoot"
        x:Class="Sqlite2.ItemsPage1"
        DataContext="{Binding DefaultViewModel, RelativeSource={RelativeSource Self}}"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:local="using:Sqlite2"
        xmlns:common="using:Sqlite2.Common"
        xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
        mc:Ignorable="d"
        >
    
        <Page.Resources>
    
            <!-- Collection of items displayed by this page -->
            <CollectionViewSource
                x:Name="itemsViewSource"
                Source="{Binding Items}"/>
    
            <!-- TODO: Delete this line if the key AppName is declared in App.xaml -->
            <x:String x:Key="AppName">Cursos</x:String>
        </Page.Resources>
    
        <!--
            This grid acts as a root panel for the page that defines two rows:
            * Row 0 contains the back button and page title
            * Row 1 contains the rest of the page layout
        -->
            
      
        <Grid Style="{StaticResource LayoutRootStyle}">
            <Grid.RowDefinitions>
                <RowDefinition Height="140"/>
                <RowDefinition Height="*"/>
            </Grid.RowDefinitions>
    
    
        
            <!-- Horizontal scrolling grid used in most view states -->
            <GridView
                
                x:Name="itemGridView"
                AutomationProperties.AutomationId="ItemsGridView"
                AutomationProperties.Name="Items"
                TabIndex="1"
                Grid.RowSpan="2"
                Padding="116,136,116,46"
                ItemsSource="{Binding Source={StaticResource itemsViewSource}}"
                ItemTemplate="{StaticResource Standard250x250ItemTemplate}"
                SelectionMode="None"
                IsSwipeEnabled="false"
                ItemClick="Event_Page" 
                IsItemClickEnabled="True"
                />
                
    
                    <TextBlock  Text="{Binding NomeCurso}" Style="{StaticResource TitleTextStyle}" TextWrapping="NoWrap" ></TextBlock>
                    <TextBlock Text="{Binding ID_Curso }" Style="{StaticResource CaptionTextStyle}" TextWrapping="NoWrap"/>
                    
               
    
                <!--Vertical scrolling list only used when snapped -->
            <ListView
                x:Name="itemListView"
                AutomationProperties.AutomationId="ItemsListView"
                AutomationProperties.Name="Items"
                TabIndex="1"
                Grid.Row="1"
                Visibility="Collapsed"
                Margin="0,-10,0,0"
                Padding="10,0,0,60"
                ItemsSource="{Binding Source={StaticResource itemsViewSource}}"
                ItemTemplate="{StaticResource Standard80ItemTemplate}"
                SelectionMode="None"
                IsSwipeEnabled="false"
               />
    
            <!-- Back button and page title -->
            <Grid>
                
                <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="Auto"/>
                    <ColumnDefinition Width="*"/>
                </Grid.ColumnDefinitions>
                <Button x:Name="backButton" Click="GoBack" IsEnabled="{Binding Frame.CanGoBack, ElementName=pageRoot}" Style="{StaticResource BackButtonStyle}"/>
                <TextBlock x:Name="pageTitle" Grid.Column="1" Text="{StaticResource AppName}" IsHitTestVisible="false" Style="{StaticResource PageHeaderTextStyle}"/>
            </Grid>
            
      
    
    
            <VisualStateManager.VisualStateGroups>
    
                <!-- Visual states reflect the application's view state -->
                <VisualStateGroup x:Name="ApplicationViewStates">
                    <VisualState x:Name="FullScreenLandscape"/>
                    <VisualState x:Name="Filled"/>
    
                    <!-- The entire page respects the narrower 100-pixel margin convention for portrait -->
                    <VisualState x:Name="FullScreenPortrait">
                        <Storyboard>
                            <ObjectAnimationUsingKeyFrames Storyboard.TargetName="backButton" Storyboard.TargetProperty="Style">
                                <DiscreteObjectKeyFrame KeyTime="0" Value="{StaticResource PortraitBackButtonStyle}"/>
                            </ObjectAnimationUsingKeyFrames>
                            <ObjectAnimationUsingKeyFrames Storyboard.TargetName="itemGridView" Storyboard.TargetProperty="Padding">
                                <DiscreteObjectKeyFrame KeyTime="0" Value="96,136,86,56"/>
                            </ObjectAnimationUsingKeyFrames>
                        </Storyboard>
                    </VisualState>
    
                    <!--
                        The back button and title have different styles when snapped, and the list representation is substituted
                        for the grid displayed in all other view states
                    -->
                    <VisualState x:Name="Snapped">
                        <Storyboard>
                            <ObjectAnimationUsingKeyFrames Storyboard.TargetName="backButton" Storyboard.TargetProperty="Style">
                                <DiscreteObjectKeyFrame KeyTime="0" Value="{StaticResource SnappedBackButtonStyle}"/>
                            </ObjectAnimationUsingKeyFrames>
                            <ObjectAnimationUsingKeyFrames Storyboard.TargetName="pageTitle" Storyboard.TargetProperty="Style">
                                <DiscreteObjectKeyFrame KeyTime="0" Value="{StaticResource SnappedPageHeaderTextStyle}"/>
                            </ObjectAnimationUsingKeyFrames>
    
                            <ObjectAnimationUsingKeyFrames Storyboard.TargetName="itemListView" Storyboard.TargetProperty="Visibility">
                                <DiscreteObjectKeyFrame KeyTime="0" Value="Visible"/>
                            </ObjectAnimationUsingKeyFrames>
                            <ObjectAnimationUsingKeyFrames Storyboard.TargetName="itemGridView" Storyboard.TargetProperty="Visibility">
                                <DiscreteObjectKeyFrame KeyTime="0" Value="Collapsed"/>
                            </ObjectAnimationUsingKeyFrames>
                        </Storyboard>
                    </VisualState>
                </VisualStateGroup>
            </VisualStateManager.VisualStateGroups>
        
        </Grid>
        
        
    </common:LayoutAwarePage>
    

    and my code behind:

    namespace Sqlite2
    {
        /// <summary>
        /// A page that displays a collection of item previews.  In the Split Application this page
        /// is used to display and select one of the available groups.
        /// </summary>
        public sealed partial class ItemsPage1 : Sqlite2.Common.LayoutAwarePage
        {
            public ItemsPage1()
            {
                this.InitializeComponent();
                
            }
                
    
    
    
    
      protected override void LoadState(Object navigationParameter, Dictionary<String, Object> pageState)
            {         
                
          
    
                var dbpath = Path.Combine(Windows.Storage.ApplicationData.Current.LocalFolder.Path, "people.db");
                using (var db = new SQLite.SQLiteConnection(dbpath))
                {
    
                  
                     List<Curso> Mylist3 = new List<Curso>();
    
                    db.RunInTransaction(() =>
                    {
                       
    
                        Mylist3 = db.Query<Curso>("Select * From Curso");
    
                    });
    
                    db.Dispose();
    
    
                    if (Mylist3.Count > 0)
                    {
                        this.itemGridView.ItemsSource = Mylist3;
                    }
    
                   
    
                        
    
    
    
                    
    
                }
            }
    
    
            //tabela Curso
            public class Curso
            {
                [AutoIncrement, PrimaryKey]
                public int ID_Curso { get; set; }
                public string NomeCurso { get; set; }
                public int EscolaID_Escola { get; set; }
                public int FormacaoID_Formacao { get; set; }
            }
    
    
            
        
    
        }
    }
    

    thanks you

    Tuesday, October 8, 2013 1:43 PM
  • try this

    <ScrollViewer VerticalScrollBarVisibility="Disabled" Grid.Column="1" HorizontalScrollBarVisibility="Auto" ZoomMode="Disabled"  >
                    <GridView Name="itemListViewss" IsRightTapEnabled="False"  ItemsSource="{Binding}" AllowDrop="True" ItemClick="itemListViewss_ItemClick" HorizontalAlignment="Center" VerticalAlignment="Top" IsItemClickEnabled="True" Margin="15,0,0,0" Height="140" Tag="0">
                    <GridView.ItemTemplate>
                        <DataTemplate>                       
                                <Grid HorizontalAlignment="Left" Height="140" Width="170" VerticalAlignment="Top" >
                                    <Image Margin="0" Source="{Binding Path=templateName}" Stretch="Fill" Width="170" Height="140" x:Name="imagegrid" PointerExited="Grid_PointerExited"/>
                                    <Grid HorizontalAlignment="Left" Height="68" Margin="0" VerticalAlignment="Bottom" Width="170" Background="#E5231F20" >
                                        <TextBlock HorizontalAlignment="Center" Foreground="White" TextWrapping="Wrap" Text="{Binding reportName}" VerticalAlignment="Center" FontSize="14" Tag="{Binding procedureName}" Margin="0,-15,0,0" PointerEntered="Grid_PointerEntered" PointerExited="Grid_PointerExited" />
                                        </Grid> 
                                </Grid>                      
                        </DataTemplate>
                    </GridView.ItemTemplate>
                </GridView>
                </ScrollViewer>

    first inside datatemplate copy code and put in sample test page inthere do static instead of binding give some text and try then put inside gridview

    • Marked as answer by Aurelien Mota Tuesday, October 8, 2013 2:24 PM
    Tuesday, October 8, 2013 1:56 PM