locked
Binding ItemSource to Listview From SQL LITE RRS feed

  • Question

  • Hi All,

    Am Developing Windows 8  Apps.

    Am Binding One values to List View.

    But What i want is Like

    I have List<string> Lst=new List<string>();

    Lst.Add(A1,B1,C1);

    Lst.Add(A2,B2,C2);

    in listview i want like

    A1

    B1

    C1

    A2

    B2

    C2

    Like This

    Till C1 i want in one row but in three lines

    That is first row contins 3 lines (A1,B1,c1)

    Any Suggestion Would Be of Great Help.

    Thanks

    Arjun.M



    Arjun


    Tuesday, January 21, 2014 12:55 PM

Answers

  • It should be this:
    <ListView x:Name="MyListView">
    <ListView.ItemTemplate>
    <DataTemplate>
    <StackPanel>
    <TextBlock Text="{Binding Age}"/>
    <TextBlock Text="{Binding Address}"/>
    <TextBlock Text="{Binding Name}"/>
    </DataTemplate>
    </ListView.ItemTemplate>
    </ListView>
    
    
    public class Person
    {
      string Age {get; set;}
      string Address {get; set;}
      string Name {get; set;}
    }
    
    override void OnNavigatedTo (...)
    {
        List<Person> MyList = new List<Person>();
        MyList.Add(new Person() {Age="25", Address="India", Name="Arjun"});
        MyList.Add(new Person() {Age="25", Address="India", Name="Rahul"});
        MyListView.ItemsSource = MyList;
    }
    


    Matt Small - Microsoft Escalation Engineer - Forum Moderator
    If my reply answers your question, please mark this post as answered.

    NOTE: If I ask for code, please provide something that I can drop directly into a project and run (including XAML), or an actual application project. I'm trying to help a lot of people, so I don't have time to figure out weird snippets with undefined objects and unknown namespaces.

    Thursday, January 23, 2014 7:05 PM
    Moderator

All replies

  • Your explanation is not clear to me. The output you've specified is simple enough to achieve by individually adding the strings one at a time:

    Lst.Add(A1);

    Lst.Add(B1);

    Lst.Add(C1);

    Lst.Add(A2);

    Lst.Add(B2);

    Lst.Add(C3);

    However, you're asking for something else which I am not sure of.  Can you please explain again?


    Matt Small - Microsoft Escalation Engineer - Forum Moderator
    If my reply answers your question, please mark this post as answered.

    NOTE: If I ask for code, please provide something that I can drop directly into a project and run (including XAML), or an actual application project. I'm trying to help a lot of people, so I don't have time to figure out weird snippets with undefined objects and unknown namespaces.

    Tuesday, January 21, 2014 2:08 PM
    Moderator
  • Hi Matt,

    i have A List<Class> Which  has many properties Like age,address name ..

    am binding this list to my list view.

    in the output 

    i want one row which contains

    age:25--Line1

    Address:India-Line2

    Name:Arjun----- Line3

     And Next Row 

    Age:25 ----  Line1

    Address:india---Line2

    Name:Rahul--Line 3

    Thanks

    Arjun


    Arjun

    Wednesday, January 22, 2014 6:12 AM
  • It should be this:
    <ListView x:Name="MyListView">
    <ListView.ItemTemplate>
    <DataTemplate>
    <StackPanel>
    <TextBlock Text="{Binding Age}"/>
    <TextBlock Text="{Binding Address}"/>
    <TextBlock Text="{Binding Name}"/>
    </DataTemplate>
    </ListView.ItemTemplate>
    </ListView>
    
    
    public class Person
    {
      string Age {get; set;}
      string Address {get; set;}
      string Name {get; set;}
    }
    
    override void OnNavigatedTo (...)
    {
        List<Person> MyList = new List<Person>();
        MyList.Add(new Person() {Age="25", Address="India", Name="Arjun"});
        MyList.Add(new Person() {Age="25", Address="India", Name="Rahul"});
        MyListView.ItemsSource = MyList;
    }
    


    Matt Small - Microsoft Escalation Engineer - Forum Moderator
    If my reply answers your question, please mark this post as answered.

    NOTE: If I ask for code, please provide something that I can drop directly into a project and run (including XAML), or an actual application project. I'm trying to help a lot of people, so I don't have time to figure out weird snippets with undefined objects and unknown namespaces.

    Thursday, January 23, 2014 7:05 PM
    Moderator