Hi there,
Can anyone give me an example of how I can programatically populate a XamDataGrid with DataRecords? The DataRecord class does not have a constructor and it looks like data can only be populated through binding? Any reason why we shouldn't populate the grid programatically without the use of bindings?
Thanks in advance!
I could be wrong, but I'd say the reason is that the records are part of the grid's visual tree. They are not an isolated concept, but created during the rendering process of the underlying data source. To me, it makes sense to isolate data and records. You can, however, programmatically assign your data in two ways. The most common one is to set the DataSource or DataContext. You can also look at the DataItems property, which provides an alternative.
List<Person> persons = GetPersons();myGrid.DataSource = persons;
The above code produces a record for every displayed Person object. However, please note that the records might not be available immediately, if you assign the data source in a control's/window's constructor (rather use the Loaded event). You might also have to define the loading mechanism of the records to RecordLoadMode.PreloadRecords:
<igDP:XamDataGrid x:Name="myGrid" RecordLoadMode="PreloadRecords">
In case you'd like to achieve something different, please elaborate a bit further...
HTH,
Philipp