Hi,
I am looking for information on how to provide data to DataGrid using Dictionary. My use case is: I have WebService that provides me a table with the content (and column names) I get know in runtime.
My current implementation of a data tuple is:
public class GridTuple : Dictionary<string, string>
{
public GridTuple(IDictionary<string, string> cv, int id) : base(cv)
{
TupleId = id;
}
public int TupleId { set; get; }
public override string ToString()
{
string result = TupleId + " ";
for (int i = 0; i < ColumnNames.Names.Count; i++)
{
result += ColumnNames.Names[i] + " " + this[ColumnNames.Names[i]] + " ";
}
return result;
}
}
...and implementation for DataGrid in xaml is:
<sdk:DataGrid AutoGenerateColumns="True" HeadersVisibility="All" x:Name="dataGrid"
HorizontalAlignment="Left" VerticalAlignment="Top"
ItemsSource="{Binding ListOfGridTuples}" MouseLeftButtonUp="dataGrid_MouseLeftButtonUp"
SelectionMode="Single" Grid.Column="1" >
<sdk:DataGrid.Columns>
<!-- ValueForColumn1 is a key in my GridTuple -->
<sdk:DataGridTextColumn Binding="{Binding [ValueForColumn1]}" />
</sdk:DataGrid.Columns>
</sdk:DataGrid>
...