+ Reply to Thread
Results 1 to 2 of 2

Thread: ADD item to multiple column listview

  1. #1

    ADD item to multiple column listview

    I have a listview in WPF and i'd like to add data to every single column but i can't.
    In windowsforms it is easy but in WPF it does not want to work at all.
    Doing that is very easy on .net 2 windowsfroms , as you only use ListViewItem.SubItem , but here in WPF i can't do that because the
    SubItem method does not exist.

    I'll be thankful if you could give me a short tutorial about how to do that
    Last edited by csharpmaster; 10-31-2012 at 04:32 AM.

  2. #2
    Steps :
    1- create a class full of Variables of getter and setter , the number of variables depends on the columns number [you will better understand it later]
    2- add a memberbinding with value exactly the same on the public class variable name you created inside xaml code [you will better understand it on example]

    Here is how to do it :
    A : create a public class
        public class ADD_NEW_DATA
            public ADD_NEW_DATA()
                // default constructor
            public ADD_NEW_DATA(string C1, string C2, string C3)
                Column_1 = C1;
                Column_2 = C2;
                Column_3 = C3;
            public string Column_1 { get; set; }
            public string Column_2 { get; set; }
            public string Column_3 { get; set; }
    B : When click on add_button do the following :
            ADD_NEW_DATA data = new ADD_NEW_DATA("Data1", "Data2", "Data3");

    C : IMPORTANT TO add a memberbinding value exactly the same on the public class you created inside xaml code :
    DisplayMemberBinding="{Binding Path=Column_1 or 2 or 3}"
    for example :
        <ListView Height="371" Name="listView1" Width="963" VerticalAlignment="Top" FlowDirection="LeftToRight" HorizontalContentAlignment="Left">
                <GridView AllowsColumnReorder="True">
                    <GridViewColumn Header="Column1" Width="130" DisplayMemberBinding="{Binding Path=Column_1}" />
                    // and so on

+ Reply to Thread

Tags for this Thread


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts