This is a migrated thread and some comments may be shown as answers.

RadMultiColumnComboBoxElement AutoGenerateColumns not working

2 Answers 260 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Saif
Top achievements
Rank 2
Saif asked on 06 May 2014, 08:41 AM
Hi,

Im trying to bind datatable in GridView GridViewMultiComboBoxColumn

GridViewMultiComboBoxColumn col = new GridViewMultiComboBoxColumn();
      col.DataSource = dtCash;
      col.DisplayMember = "Name";
      col.ValueMember = "td";
      col.FieldName = "Id";
      col.Name = "Description";
      col.HeaderText = "Name";
      col.DropDownStyle = RadDropDownStyle.DropDown;
      this.gridView.Columns.Add(col);

bool isColumnAdded;
    private void gridView_CellEditorInitialized(object sender, GridViewCellEventArgs e)
    {
      if (this.gridView.CurrentColumn is GridViewMultiComboBoxColumn)
      {
        if (!isColumnAdded)
        {
          isColumnAdded = true;
          RadMultiColumnComboBoxElement editor = (RadMultiColumnComboBoxElement)this.gridView.ActiveEditor;
          editor.AutoFilter = true;

          editor.EditorControl.MasterTemplate.AllowAddNewRow = false;
          editor.EditorControl.MasterTemplate.AllowCellContextMenu = false;
          editor.EditorControl.MasterTemplate.AllowColumnChooser = false;
          editor.EditorControl.MasterTemplate.AutoGenerateColumns = false;
          editor.EditorControl.MasterTemplate.AutoSizeColumnsMode = GridViewAutoSizeColumnsMode.Fill;
          editor.EditorControl.MasterTemplate.AllowRowResize = false;

          GridViewTextBoxColumn colCode = new GridViewTextBoxColumn();
          GridViewTextBoxColumn colName = new GridViewTextBoxColumn();
          colCode.FieldName = "Code";
          colCode.HeaderText = "Code";
          colCode.Name = "Code";
          colName.FieldName = "Name";
          colName.HeaderText = "Name";
          colName.Name = "Name";
          colName.IsVisible = false;
          editor.EditorControl.MasterTemplate.Columns.AddRange(new GridViewDataColumn[] {
            colCode,
            colName});
          editor.AutoSizeDropDownToBestFit = true;

          FilterDescriptor filterDescriptor = new FilterDescriptor();
          filterDescriptor.PropertyName = "Name";
          filterDescriptor.Operator = FilterOperator.Contains;
          editor.EditorControl.MasterTemplate.FilterDescriptors.AddRange(new FilterDescriptor[] {
            filterDescriptor});
        }
      }
    }


I Set the AutoGenerateColumns to true to show only two columns i want.. but when i run, all columns coming from the datable also shows.

I dont know exactly what is wrong with my code.

2 Answers, 1 is accepted

Sort by
0
Dimitar
Telerik team
answered on 07 May 2014, 02:52 PM
Hello Saif,

Thank you for writing.

In this case you should use the CellBeginEdit event instead of CellEditorInitialized, because in the second the underlying grid is already initialized and it already has some columns. Detailed information is available in the following article: GridViewMultiComboBoxColumn.

Also please note that the column that is used as ValueMember should exist in the underlying grid even if it is not visible. 

Let me know if you have additional questions.

Regards,
Dimitar
Telerik
 
Check out Telerik Analytics, the service which allows developers to discover app usage patterns, analyze user data, log exceptions, solve problems and profile application performance at run time. Watch the videos and start improving your app based on facts, not hunches.
 
0
Saif
Top achievements
Rank 2
answered on 10 May 2014, 05:47 AM
Thanks Dimitar
Tags
GridView
Asked by
Saif
Top achievements
Rank 2
Answers by
Dimitar
Telerik team
Saif
Top achievements
Rank 2
Share this question
or