Note that there are some explanatory texts on larger screens.

plurals
  1. POWPF Add Row to XML Bound DataGrid
    primarykey
    data
    text
    <p>When I debug, I am unable to add a row to my DataGrid.</p> <p><strong>Setting:</strong> I have an XML file (C:\test.xml) that I use as my DataGrid's XmlDataProvider</p> <p><strong>XAML:</strong></p> <pre><code>&lt;Window x:Class="iDraft.Window1" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" Height="185" Width="176"&gt; &lt;Grid&gt; &lt;Grid.DataContext&gt; &lt;XmlDataProvider x:Name="myData" XPath="Table/ENTRY" /&gt; &lt;/Grid.DataContext&gt; &lt;DataGrid AutoGenerateColumns="False" ItemsSource="{Binding}" CanUserAddRows="True"&gt; &lt;DataGrid.Columns&gt; &lt;DataGridTextColumn Header="Text" Binding="{Binding XPath=text, Mode=TwoWay}"/&gt; &lt;DataGridTemplateColumn Header="Combobox"&gt; &lt;DataGridTemplateColumn.CellTemplate&gt; &lt;DataTemplate&gt; &lt;ComboBox Text="{Binding XPath=combo, Mode=TwoWay}"&gt; &lt;ComboBoxItem&gt;0&lt;/ComboBoxItem&gt; &lt;ComboBoxItem&gt;1&lt;/ComboBoxItem&gt; &lt;ComboBoxItem&gt;2&lt;/ComboBoxItem&gt; &lt;ComboBoxItem&gt;3&lt;/ComboBoxItem&gt; &lt;ComboBoxItem&gt;4&lt;/ComboBoxItem&gt; &lt;/ComboBox&gt; &lt;/DataTemplate&gt; &lt;/DataGridTemplateColumn.CellTemplate&gt; &lt;/DataGridTemplateColumn&gt; &lt;/DataGrid.Columns&gt; &lt;/DataGrid&gt; &lt;/Grid&gt; &lt;/Window&gt; </code></pre> <p><strong>C#:</strong></p> <pre><code>using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Windows; using System.Windows.Controls; using System.Windows.Data; using System.Windows.Documents; using System.Windows.Input; using System.Windows.Media; using System.Windows.Media.Imaging; using System.Windows.Navigation; using System.Windows.Shapes; using System.Xml; namespace iDraft { public partial class Window1 : Window { public Window1() { InitializeComponent(); myData.Source = new Uri(@"C:\test.xml"); } } } </code></pre> <p><strong>XML (test.xml):</strong></p> <pre><code>&lt;?xml version="1.0" encoding="utf-8" ?&gt; &lt;Table&gt; &lt;ENTRY&gt; &lt;text&gt;1&lt;/text&gt; &lt;combo&gt;1&lt;/combo&gt; &lt;/ENTRY&gt; &lt;ENTRY&gt; &lt;text&gt;2&lt;/text&gt; &lt;combo&gt;1&lt;/combo&gt; &lt;/ENTRY&gt; &lt;/Table&gt; </code></pre> <p>I dug through some old vb.net code and found the following:</p> <pre><code>Imports System.Xml Imports System.Data Class MainWindow Private Sub Window_Loaded(ByVal sender As System.Object, ByVal e As System.Windows.RoutedEventArgs) Handles MyBase.Loaded Dim xmlFile As XmlReader Dim ds As New DataSet xmlFile = XmlReader.Create("C:\test.xml", New XmlReaderSettings()) ds.ReadXml(xmlFile) xmlFile.Close() myData.Source = ds.Tables(0) End Sub End Class </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload