Search code examples
wpfmvvminfragisticsxamdatagridxamgrid

AutoGeneratingColumn event in Infragistics xamgid or xamdatagrid?


I work with wpf & MVVM. I have a page with datagrid which is bound to a datatable from viewmodel . In datagrid auto generate column property is true . But I need some coulmns to be combo box . So i use AutoGeneratingColumn event of datagrid to achieve that. In code behind event method looks like this.

   private void DataGrid_AutoGeneratingColumn(object sender, DataGridAutoGeneratingColumnEventArgs e)
    {
       if (e.PropertyName == "Gender")
        {
            var cb = new DataGridComboBoxColumn();
            cb.ItemsSource = (DataContext as EmpDetailsWindowViewModel).GenderDataTable.DefaultView;
            cb.DisplayMemberPath = "Name";
            cb.SelectedValuePath = "Code";
            cb.SelectedValueBinding = new Binding("Gender");
            e.Column = cb;
       }
    }

Now as per new requirement I have to use infragistics xamDatagrid or Xamgrid for filtering values and for some other features which infragistics grid provide . But I am not finding AutoGeneratingColumn event in both of the infragistics grids . How can achieve this functionality in infragistics grids?


Solution

  • In that case subscribe to the FieldLayoutInitialized event and write appropriate code logic.

    I just wrote this code:

    private void XamDataGrid_FieldLayoutInitialized_1(object sender,   Infragistics.Windows.DataPresenter.Events.FieldLayoutInitializedEventArgs e)
        {
            var comboGenderField = e.FieldLayout.Fields["Gender"];
            if (comboGenderField != null)
            {
                var xamComboEditorStyle = new Style(typeof(XamComboEditor));
                var itemsProviderSetter = new Setter(XamComboEditor.ItemsProviderProperty,
                                                     this.FindResource("cmbGenderProvider"));
                xamComboEditorStyle.Setters.Add(itemsProviderSetter);
    
                comboGenderField.Settings.EditorStyle = xamComboEditorStyle;
                comboGenderField.Settings.EditAsType = typeof (int);
            }
        }
    

    Refer this for more info: http://help.infragistics.com/Help/NetAdvantage/WPF/2012.2/CLR4.0/html/xamComboEditor_Setting_the_xamComboEditor_as_an_Editor_of_a_Field_Programmatically.html