Click here to Skip to main content
15,867,568 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,
I am populating my DataGrid control using an XmlDataProvider, I have defined columns along with XPath for each column. I want to get the cursor in my ViewModel when the user edits any cell along with the Row Details. How can I achieve this.

Please find my code below:

C#
dataProvider = new XmlDataProvider();
System.Xml.XmlDocument doc = new System.Xml.XmlDocument();
doc.Load(@"F:\Work\Samples\WPF\XML Binding Samples\tCustomers2.xml");
dataProvider.Document = doc;
dataProvider.XPath = "DocumentElement";

XAML 


XML
<DataGrid x:Name="dgXml" DataContext="{Binding DataProvider}" ItemsSource="{Binding XPath=tCustomers}" AutoGenerateColumns="False" Grid.Row="1">
    <DataGrid.Columns>
        <DataGridTextColumn IsReadOnly="True" Header="CustomerId" Binding="{Binding XPath=CustomerId/text()}" Width="*"/>
        <DataGridTextColumn Header="Customer Name" Binding="{Binding XPath=CustomerName/text()}" Width="*"/>
         <DataGridTextColumn Header="Customer Address" Binding="{Binding XPath=Address/text()}" Width="*"/>                
     </DataGrid.Columns>
</DataGrid>


XML File:
XML
<NewDataSet>
  <tCustomers>
    <CustomerId>1</CustomerId>
    <CustomerName>Customer1</CustomerName>
    <Address>asdf</Address>
    <BranchId>1</BranchId>
  </tCustomers>
  <tCustomers>
    <CustomerId>2</CustomerId>
    <CustomerName>Customer2</CustomerName>
    <Address>kgh</Address>
    <BranchId>1</BranchId>
  </tCustomers>
  <tCustomers>
    <CustomerId>3</CustomerId>
    <CustomerName>Customer3</CustomerName>
    <Address>kgh</Address>
    <BranchId>1</BranchId>
  </tCustomers>
  <tBranches>
    <BranchId>1</BranchId>
    <BranchName>Branch1</BranchName>
    <Address>Hydrebad</Address>
  </tBranches>
  <tBranches>
    <BranchId>2</BranchId>
    <BranchName>Branch2</BranchName>
    <Address>Bangalore</Address>
  </tBranches>
</NewDataSet>
Posted

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