[MainPage.Xaml.cs]
public partial class MainPage : ContentPage
{
public MainPage()
{
..........
..........
this.myGrid.QueryUnboundColumnValue += MyGrid_QueryUnboundColumnValue;
}
private void MyGrid_QueryUnboundColumnValue(object sender, GridUnboundColumnEventArgs e)
{
if (e.UnboundAction == UnboundActions.QueryData)
{
Dictionary<string, CellData> rowData = e.Record.GetType().GetField("_data", BindingFlags.NonPublic | BindingFlags.Instance).GetValue(e.Record) as Dictionary<string, CellData>;
var cellData = rowData.FirstOrDefault(x => x.Key.Equals(e.Column.MappingName)).Value as Cel
e.Value = cellData.Value;
}
}
private void ViewModelOnCollectionChanged(object sender, NotifyCollectionChangedEventArgs e)
{
.......
.......
myGrid.Columns.Clear();
myGrid.Columns.Add(orderIdCol);
myGrid.Columns.Add(employeeCol);
foreach (var key in keys)
{
GridUnboundColumn column = new GridUnboundColumn();
column.Expression = key;
column.MappingName = key;
column.HeaderText = key;
column.Width = 100;
myGrid.Columns.Add(column);
}
.......
.......
}
} |