There are some problem with fill datagrid with dynamic source. For example, I want to fill datagrid with objects that has various parameters. This parameters display dynamic data from database. Columns count may be changed and parameters count may be changed but counts equals. Fill headers:
private void DataSourseChanged(SourceList sourceList)
{
Columns.Clear();
Columns.Add(new DataGridTextColumn());
if (sourceList != null)
{
foreach (var item in sourceList.ColumnsHeaders)
Columns.Add(new DataGridTextColumn { Header = item });
}
}
public class SourceList
{
private readonly IList _columnsHeaders;
private readonly IList _rowsHeaders;
private readonly IList _dataRows;
public IList ColumnsHeaders
{
get { return _columnsHeaders; }
}
public IList RowsHeaders
{
get { return _rowsHeaders; }
}
public IList DataRows
{
get { return _dataRows; }
}
public SourceList(IList rowsHeaders, IList columnsHeaders, IList dataRows)
{
_rowsHeaders = rowsHeaders;
_columnsHeaders = columnsHeaders;
_dataRows = dataRows;
}
}
I want to fill headers and rows (rows as merge of _rowsHeaders[i] in first column and other columns with _datarows[i]) but rows fills only with objects that has properties. May I fill datagrid with dynamic length?