I am creating a DataTable with the following function:
public DataTable getTable() {
DataTable T = new DataTable();
T.Columns.Add("Type / Control", System.Type.GetType("System.String"));
T.Columns.Add("Investment cost", System.Type.GetType("System.Double"));
T.Columns.Add("Removal cost", System.Type.GetType("System.Double"));
T.Columns.Add("Maintainance cost", System.Type.GetType("System.Double"));
string name;
foreach (CatalogueEntry entry in this.CatalogueList) {
if (entry.type != EntryType.Battery) {
name = entry.PF_type_elm.Name.GetString();
} else {
BatteryCatalogueEntry bce = (BatteryCatalogueEntry)entry;
name = bce.control.Name;
}
DataRow row = T.NewRow();
row[0] = name;
row[1] = entry.InstallationCost;
row[2] = entry.RemovalCost;
row[3] = entry.MaintenanceCost;
T.Rows.Add(row);
}
return T;
}
and I set it to a data grid like this:
DataTable T = getTable();
this.libraryDataGrid.ItemsSource = T.DefaultView;
The first problem is that the first column shows no values (they should be string values) and when I try to write something in the first colum it gives the "Two-way binding requires Path or XPath" error. The columns marked as double are fine and they are updatable.
I have seen this question being solved by putting {get;set;} in the data structures but I don't see how that aplies here.
Just in case, the XAML code is:
<DataGrid x:Name="libraryDataGrid" Margin="0,0,0,30" GridLinesVisibility="Horizontal" HorizontalGridLinesBrush="Gray" Background="{x:Null}"/>
There is no binding there.
see: “Two-way binding requires Path or XPath” when edit wpf datagrid see: How do I fix “Two-way binding requires Path or XPath” exception in WPF Datagrids?
Thanks