.NET Framework Bookmark and Share   
 index > Windows Presentation Foundation (WPF) > Loading a ListView from a DataSet
 

Loading a ListView from a DataSet

Hi, i have a dataset that reads an xml file. What i'm trying to do is have the first 3 child nodes viewed in a listView in 3 columns. When the listView Loads it only shows the first row of the dataset. What i need is every row to show up in the listView.


<?xml version="1.0" standalone="yes"?>
<FileList>
<file>
<serverfile>AppCopy.exe</serverfile>
<moddate>9/12/2006 11:14:54 PM</moddate>
<localpath>c:\Program Files\RTGSoftwareUpdate</localpath>
<localfile />
<action>copy</action>
<register />
<includelogins />
<excludelogins />
<shellcommand />
</file>
<file>
<serverfile>RegAsm.exe</serverfile>
<moddate>9/23/2005 12:28:56 PM</moddate>
<localpath>c:\Program Files\RTGSoftwareUpdate</localpath>
<localfile />
<action>copy</action>
<register />
<includelogins />
<excludelogins />
<shellcommand />
</file>
</FileList>

The xaml code for the listView shows something like this:

<ListView Margin="5,50,5,94" Name="listView1">

<ListView.View>

<GridView>

<GridViewColumn Header="File Name:" Width="225" DisplayMemberBinding="{Binding Path=file/serverfile}"/>

<GridViewColumn Header="Modified Date:" Width="100" DisplayMemberBinding="{Binding Path=file/moddate}"/>

<GridViewColumn Header="Local Path:" Width="120" DisplayMemberBinding="{Binding Path=file/localpath}"/>

</GridView>

</ListView.View>

</ListView>

The Behind Code Looks Like This:

private void LoadXml(object sender, RoutedEventArgs e)

{

ds.ReadXml(@"c:\xml\filelist2.xml");

Binding bind = new Binding();

bind.Source = ds;

listView1.SetBinding(ListView.ItemsSourceProperty, bind);

}

Could someone point me in the right direction? Thanks.

A.Carter

change the Binding code to

Binding bind = new Binding("file");

bind.Source = ds;

and DisplayMemberBinding's to

<GridViewColumn Header="File Name:" Width="225" DisplayMemberBinding="{Binding Path=serverfile}"/>

<GridViewColumn Header="Modified Date:" Width="100" DisplayMemberBinding="{Binding Path=moddate}"/>

<GridViewColumn Header="Local Path:" Width="120" DisplayMemberBinding="{Binding Path=localpath}"/>

lee d

change the Binding code to

Binding bind = new Binding("file");

bind.Source = ds;

and DisplayMemberBinding's to

<GridViewColumn Header="File Name:" Width="225" DisplayMemberBinding="{Binding Path=serverfile}"/>

<GridViewColumn Header="Modified Date:" Width="100" DisplayMemberBinding="{Binding Path=moddate}"/>

<GridViewColumn Header="Local Path:" Width="120" DisplayMemberBinding="{Binding Path=localpath}"/>

lee d

thanks lee that worked perfectly. I don't understand though why it works...I mean isn't the code basically the same? The way it looks i would expect it to work the same. Thank you again for your help i'm new to WPF and the framework is much diffrent from 2.0 and i'm trying to get used to it. Are there any good books out there for WPF (3.0) yet?

Carter

A.Carter
lee d

You can use google to search for other answers

Custom Search

More Threads

• Clickable text in FlowDocument
• The new RichTextBox or how to find old functionality in WPF?
• Collection binding problem
• Is there a way of making a bind a treeview with the filesystem and start in the my computer like windows explorer?
• Binding to an Element of a Dictionary?
• What is the proper way to reuse a small bit of WPF code (such as a Path) multiple times as button content?
• Blurry images
• ListBox - need to make items non-selectable but still be able to interact with the contents of row
• hosting windows form control in WPF removes visual style
• RichTextBox Limitation #1: Cannot Deserialize User Controls