I have a DataGrid that shows Data from a DataTable which is bound into my code-behind. (The TableData I want to draw is depending on the selectedItem of a ComboBox. It changes the column headers when changing the selectedItem, so i think this is not a problem. See this in the two prictures below)
So, the DataGrid in .xaml looks like this:
<DataGrid AutoGenerateColumns="True" ItemsSource="{Binding Path=CurrentTable.CurrentDataTable.DefaultView}" >
</DataGrid>
In my ViewModel I have an object named "CurrentTable" from the class TableInformation. It looks like this:
public class TableInformation : BaseViewModel
{
public string TableName; //with geter, seter
public DataTable CurrentDataTable; //with geter, seter
}
with inheritates from BaseViewModel because of the PropertyChanged Event (this works fine!).
When loading my CurrentTable, the code looks like this:
public void LoadInitialJsonData()
{
// Fill all table data
QtyTopLevelKeys = BPPCjson_if.BPPCjson_getTableCount(context);
for (int curTableIdx = 0; curTableIdx < QtyTopLevelKeys; curTableIdx )
{
int qtyRows = // rowCount
int qtyCols = // columnCount
var curDataTable = new DataTable();
// set Header Name for each column
for (int curCol = 0; curCol < qtyCols; curCol )
{
string curHeader = //unique headername from interface
if (!curDataTable.Columns.Contains(curHeader))
{
curDataTable.Columns.Add(curHeader, typeof(string));
// PropertyChangedEvent has no effect here
}
}
// set Value for each cell
for (int curRow = 0; curRow < qtyRows; curRow )
{
DataRow curRowData;
curRowData = curDataTable.NewRow();
for (int curCol = 0; curCol < qtyCols; curCol )
{
string data = //value of cell
curRowData[curCol] = data;
}
curDataTable.Rows.Add(curRowData);
}
curDataTable.TableName = //unique Name
TableInformation ti = new TableInformation(curTableName, qtyRows, qtyCols, curDataTable);
AllTables.Add(ti);
}
}
Unfortunately, the shown Table looks like this:
Cell-values not shown but cells are existing 1
Cell-values not shown but cells are existing 2
Can you help me? Why does it show the correct amount of Rows/Cells but without any content?
It also says that I have binding errors. But i do not really understand why... Binding errors
Thank you very much for your help!!!
CodePudding user response:
I found it by myself and with a little help of @ASh.
My "unique headernames" did contain dots.
All I did was replacing googling what could help.