Hello All,
Please consider this code:
void BindExistingXamDataGridToNewlyGeneratedData() {
m_dataGrid.DataSource =
null;
m_dataGrid.FieldLayouts.Clear();
m_dataGrid.DataSource = TargetViewReportDataService.TargetViewReportData;
Field newField = new Field();
newField.Name =
"Event";
newField.Label =
m_dataGrid.FieldLayouts[0].Fields.Add(newField);
// Add other fields...
}
In addition to the above, I am setting XamDataGrid.FieldLayoutSettings.AutoGenerateFields to false in xaml.
*In some cases*, I get an exception for an invalid index ([0] in the code above). In all cases, however, the XamDataGrid has been long constructed before I attempt the maneuver shown above.
I could add the following:
m_dataGrid.FieldLayouts.Add(
new FieldLayout());
This seems to work, but I don't see this being done in the example that led me to implement the code above.
So, I'll ask...
Why would XamDataGrid.FieldLayouts sometimes contain elements and other times not? When does XamDataGrid add elements to it, and when must I add elements to it? I ask this keeping in mind that I set AutoGenerateFields to false.
Thanks,
Dave
Hello Dave,
If you want to add your fields manually in procedural code, you can do this in the FieldLayoutInitialiezd event. In this event, the FieldLayout is ready and you can add your fields in there. You can also do that in any other event after that - like the Loaded.
As far as the formatting, you can use the CopyAsHTML add-in for the Visual Studio to get a nice formatting in any post. You can find it here.
Sorry for the messed-up formatting. I struggled a lot to get it looking decent before I clicked "Post", but what appeared in the forum does not look like what I had in my editor. I've noticed the forum editor doube-spaces everything and that code does not copy and paste in well at all. I've always struggled with using these forums' editors; is there a doc out there that gives tips on using them?