I've successfully bound data to the grid; however, when the model bound to the grid changes the results don't show up in the grid until I give focus to that row. For the purposes of this issue, don't worry about the meaning of the "scans" and "_snc" objects as they have nothing to do with the issue.
Here is where I successfully bind to a model called "ComparisonScansViewModel" which has a public "List<ComparisonScanViewModel> Scans" property.
await Task.Factory.StartNew(() =>
{
// source scans for comparison
_model = new ComparisonScansViewModel(_snc, scans);
});
BatchComparisonGrid.DataSource = _model.Scans;
Here is the model code (loads up fine)
public class ComparisonScansViewModel
{
public ComparisonScansViewModel(SNC snc, List<Scan> scans)
{
Scans = new List<ComparisonScanViewModel>();
scans.ForEach(s =>
{
Scans.Add(new ComparisonScanViewModel()
{
Id = s.ScanId,
Type = snc.Values.GetInstance(s.Type).Text,
Field = s.FieldSize.ToString(),
Energy = s.EnergyForDisplay,
Depth = s.Depth,
});
});
}
public List<ComparisonScanViewModel> Scans;
}
public class ComparisonScanViewModel
{
public int Id { get; set; }
public string Type { get; set; }
public string Field { get; set; }
public string Energy { get; set; }
public decimal? Depth { get; set; }
public decimal Gamma { get; set; }
}
In the code below I am hard coding the value of a property in my model named "Gamma". When the grid is first shown this value is '0' and when the value changes in a dropdownlist I am going to properly update the "Gamma" value; however, for the purposes of debugging I am simply hard coding for now.
private async void ReferenceProjectDropDownList_SelectedValueChanged(object sender, EventArgs e)
{
if (null != _model)
{
BatchComparisonWaitingBar.Visibility = Telerik.WinControls.ElementVisibility.Visible;
BatchComparisonWaitingBar.StartWaiting();
BatchComparisonStatusLabel.Text = "Calculating gamma...";
// calculate the passing % (gamma) for each item in the table
await Task.Factory.StartNew(() =>
{
for (int i = 0; i < _model.Scans.Count; i++)
{
//Thread.Sleep(500);
ComparisonScanViewModel sm = _model.Scans[i];
sm.Gamma =250m;
}
});
BatchComparisonWaitingBar.Visibility = Telerik.WinControls.ElementVisibility.Collapsed;
BatchComparisonWaitingBar.StopWaiting();
BatchComparisonStatusLabel.Text = "Ready";
}
}
When this event above is fired, the values in the model ARE updated; however, the results of this update are NOT reflected in the UI. I have to scroll through the grid view and/or click on a row to see the value change in the grid.