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
305
XamDataGrid - help on FieldLayoutInitialized event
posted

Hello,

I am using observable collection of StaffMember and which as has 3 members - StaffCategory(string), StaffTypes(string), Staff(List)

ObservableCollection<StaffMember> StaffMembers

 

StaffCategory and StaffTypes are column 1 and 2 which are constant and created in XAML view as a fields of XamDataGrid.

 

Depending on number of Staff, multiple columns gets populated column3 onwards . All this operation happening on button click. After this, I would like to update FieldLayout depending on number of Staff in collection.

 

 

If I use xamDataGrid_FieldLayoutInitialized then fieldlayout shows all columns. This done from constructor.

 

private void Xdg_OnFieldLayoutInitialized(object sender, Infragistics.Windows.DataPresenter.Events.FieldLayoutInitializedEventArgs e)

        {

            var staffMember = this.ViewModel.StaffMembers.First();

 

            for (Int32 i = 0; i < staffMember.Staff.Count; i++)

            {

                var field = new UnboundField

                {

                    Name = staffMember.Staff[i].Name,

                    BindingMode = BindingMode.TwoWay,

                    BindingPath = new PropertyPath(String.Format("Staff[{0}].Value", i))

                };

 

                field.Settings.EditAsType = typeof(String);

 

                e.FieldLayout.Fields.Add(field);

            }

        }

 

However, when I doing using button click.. it is not showing columns

 

private void BtnGenerate_OnClick(object sender, RoutedEventArgs e)

        {

            var staffMember = this.ViewModel.StaffMembers.First();

 

for (Int32 i = 0; i < StaffMember.Staff.Count; i++)

            {

                var field = new UnboundField

                {

                    Name = StaffMember.Staff[i].Name,

                    BindingMode = BindingMode.TwoWay,

                    BindingPath = new PropertyPath(String.Format("Staff[{0}].Value", i))

                };

 

                field.Settings.EditAsType = typeof(String);

 

                xdg.FieldLayouts[0].Fields.Add(field);

 

            }

                }

 

Please help me on this if I am missing anything here.

Parents
  • 34510
    Offline posted

    Hi Sagar,

    I tried reproducing this in a sample but so far I haven't had any luck.  Here is the sample I built.  When I run it and press the button to add the UnboundFields I can see those fields appear in the XamDataGrid.  I'm not sure why it's not working for you.  Can you modify my sample to reproduce your issue and then send me back to me so I can debug it?

    PopulatingFieldsDynamically.zip
Reply Children