Each column in the listviewitem is rendered based on the definition of the GridView, so there is no real concept of column numbers. What you do is bind objects to the items listview source and create listviewitems from it. So there are a few hoops to slip through.
This link provides an example of how to perform some simple object data bindings. The advantage of this is that the binding structure that you have for development time can be reused for runtime if you set the datacontext / itemsource data source to an empty object instead of a static one in XAML.
If you are doing this to show examples or you have a static data source that you want to use, I would recommend using XmlDataProvider . Then you change your ListView so that
<ListView IsSynchronizedWithCurrentItem="True" Margin="8,68,304,188" BorderThickness="2,2,2,2"> <ListView.View> <GridView> <GridViewColumn Width="150" Header="Column1" DisplayMemberPath="{Binding XPath=/A/B}"/> <GridViewColumn Width="150" Header="Column2" DisplayMemberPath="{Binding XPath=/A/C"/> </GridView> </ListView.View> <ListViewItem> </ListViewItem> </ListView>
<ListView IsSynchronizedWithCurrentItem="True" Margin="8,68,304,188" BorderThickness="2,2,2,2"> <ListView.View> <GridView> <GridViewColumn Width="150" Header="Column1" DisplayMemberPath="{Binding XPath=/A/B}"/> <GridViewColumn Width="150" Header="Column2" DisplayMemberPath="{Binding XPath=/A/C"/> </GridView> </ListView.View> <ListViewItem> </ListViewItem> </ListView>
apandit
source share