Click here to Skip to main content
15,881,858 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have a XML file (see format below - only two entries are shown) which contains a list of authors.
I'd like to list all authors' id (Typically 'au_id' tag in the XML) in a VB.NET WPF ListBox and based on the selection in that ListBox, populate a VB.NET WPF DataGrid with some or all authors' remaining information (e.g. au_lname, au_fname, phone).

<authors_table>
  <authors>
    <au_id>172-32-1176</au_id>
    <au_lname>White</au_lname>
    <au_fname>Johnson</au_fname>
    <phone>408 496-7223</phone>
    <address>10932 Bigge Rd.</address>
    <city>Menlo Park</city>
    <state>CA</state>
    <zip>94025</zip>
    <contract>true</contract>
  </authors>
  <authors>
    <au_id>213-46-8915</au_id>
    <au_lname>Green</au_lname>
    <au_fname>Margie</au_fname>
    <phone>415 986-7020</phone>
    <address>309 63rd St. #411</address>
    <city>Oakland</city>
    <state>CA</state>
    <zip>94618</zip>
    <contract>true</contract>
  </authors>
...

The following code does not work: I can display the correct information in the ListBox but when I select one id in that ListBox, the DataGrid is never populated with the expected data:

<window x:class="MainWindow" xmlns:x="#unknown">
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="MainWindow" Height="350" Width="525">
<window.resources>
    <XmlDataProvider x:Key="XmlData" Source="E:\CMT\Automation\Testarea\Authors.xml"/>
</window.resources>
<grid>
    <listbox name="ListBox1" itemssource="{Binding Source={StaticResource XmlData}, XPath=Authors_Table/authors}" displaymemberpath="au_id" horizontalalignment="Left" height="202" margin="10,10,0,0" verticalalignment="Top" width="129" />
    <datagrid datacontext="{Binding ElementName=ListBox1, XPath=SelectedItem}" horizontalalignment="Left" margin="155,10,0,0" verticalalignment="Top" height="202" width="353">
        <datagrid.columns>
            <datagridtextcolumn x:name="FNameCol" binding="{Binding XPath=au_fname}" header="First Name" />
            <datagridtextcolumn x:name="LNameCol" binding="{Binding XPath=au_lname}" header="Last Name" />
            <datagridtextcolumn x:name="PhoneCol" binding="{Binding XPath=phone}" header="Phone" />
        </datagrid.columns>
    </datagrid>
</grid>


I obviously miss something in the way I bind the two WPF controls but I can't figure out what. If you have an idea, thanks in advance for your help.</window></authors_table>
Posted
Comments
Kenneth Haugland 23-Sep-15 10:22am    
http://www.codeproject.com/Articles/26875/WPF-XmlDataProvider-Two-Way-Data-Binding

1 solution

Dear friend,
I have already explained by a sample,your problem.This is a unique method I have evolved.Do follow this article.If you do not understand,please write to me.

Article available at:-

http://www.filehosting.org/file/details/495815/PROJ-13.rar[^]

I am extremely sorry for the >than one year delay.Actually I started my wpf tutorials only from Feb 2015.This article was uploaded around July 2015.Go through this.The principle is the same for any xml file-however complicated they are.

This will help you to simplify the procedure very much.

Regards and Blessings,
Venkatraman
(aka)kvinvisibleguy

See all my articles at

http://www.dreamincode.net/forums/topic/370955-wpf-helper/page__pid__2124851__st__0entry2124851



http://www.dreamincode.net/forums/topic/370955-wpf-helper/page__st__15__gopid__2129630entry2129630

http://www.dreamincode.net/forums/topic/370955-wpf-helper/page__st__30
 
Share this answer
 
Comments
Thanks7872 23-Sep-15 12:19pm    
Why you are posting links to some external websites? Why one should download something? You have been given enough space to explain. Use it.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900