Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
785
XamDataGrid.FieldLayouts is Empty
posted

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 =

"Event";

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