Completed
Last Updated: 19 Aug 2016 09:51 by ADMIN
ADMIN
George
Created on: 03 Feb 2014 08:28
Category: MultiColumnCombo
Type: Bug Report
0
FIX. RadMultiColumnComboBox - when RadMultiColumnComboBoxElement is a child of a cell it throws exception and does not initialize its datasource
To reproduce:
Create a ListView or GridView cell element. For example:
public class FilterGroupByCell : DetailListViewDataCellElement
    {
        private RadMultiColumnComboBoxElement multiColumnComboBox = new RadMultiColumnComboBoxElement();
        public FilterGroupByCell(DetailListViewVisualItem owner, ListViewDetailColumn column) :
            base(owner, column) { }

        protected override void CreateChildElements()
        {
            base.CreateChildElements();

            this.multiColumnComboBox.AutoSizeDropDownToBestFit = true;
            multiColumnComboBox.DropDownSizingMode = SizingMode.UpDownAndRightBottom;
            multiColumnComboBox.EditorControl.MasterTemplate.AutoGenerateColumns = false;

            GridViewTextBoxColumn column = new GridViewTextBoxColumn("CustomerID");
            column.HeaderText = "Customer ID";
            multiColumnComboBox.Columns.Add(column);
            column = new GridViewTextBoxColumn("ContactName");
            column.HeaderText = "Contact Name";
            multiColumnComboBox.Columns.Add(column);
            column = new GridViewTextBoxColumn("ContactTitle");
            column.HeaderText = "Contact Title";
            multiColumnComboBox.Columns.Add(column);
            column = new GridViewTextBoxColumn("Country");
            column.HeaderText = "Country";
            multiColumnComboBox.Columns.Add(column);
            column = new GridViewTextBoxColumn("Phone");
            column.HeaderText = "Phone";
            multiColumnComboBox.Columns.Add(column);

            this.Children.Add(multiColumnComboBox);
        }

        public override void Synchronize()
        {
            base.Synchronize();
            this.Text = "";

            if (base.Row == null)
            {
                return;
            }

            this.CurrentFilter = (MFilter)base.Row.DataBoundItem;

            if (CurrentFilter.CustomListRecordId == "1")
                multiColumnComboBox.Visibility = Telerik.WinControls.ElementVisibility.Collapsed;

            DataTable table1 = new DataTable("test");
            table1.Columns.Add("CustomerID");
            table1.Columns.Add("ContactName");
            table1.Columns.Add("ContactTitle");
            table1.Columns.Add("Country");
            table1.Columns.Add("Phone");

            table1.Rows.Add(1, "Ivan Petrov", "2", "2", "2");
            table1.Rows.Add(2, "Stefan Muler", "2", "2", "2");
            table1.Rows.Add(3, "Alexandro Ricco", "2", "2", "2");

            multiColumnComboBox.DataSource = table1;
            multiColumnComboBox.DisplayMember = "ContactName";
        }

        public MFilter CurrentFilter { get; set; }
    }

Workaround:
Create a custom RadMultiColumnComboBoxElement:
public class MyRadMultiColumnComboBoxElement : RadMultiColumnComboBoxElement
{
    protected override void OnParentChanged(Telerik.WinControls.RadElement previousParent)
    {
        if (this.IsPopupOpen)
        {
            this.ClosePopup(RadPopupCloseReason.CloseCalled);
        }

        if (this.Parent != null && this.Parent.ElementTree != null && this.Parent.ElementTree.Control is RadGridView)
        {
            base.OnParentChanged(previousParent);
        }
    }

    protected override Type ThemeEffectiveType
    {
        get
        {
            return typeof(RadMultiColumnComboBoxElement);
        }
    }
}

In order to be able to set a DataSource you need to create a new BindingContext prior setting setting the DataSource:

DataTable table1 = new DataTable("test");
table1.Columns.Add("CustomerID");
table1.Columns.Add("ContactName");
table1.Columns.Add("ContactTitle");
table1.Columns.Add("Country");
table1.Columns.Add("Phone");

table1.Rows.Add(1, "Ivan Petrov", "2", "2", "2");
table1.Rows.Add(2, "Stefan Muler", "2", "2", "2");
table1.Rows.Add(3, "Alexandro Ricco", "2", "2", "2");

multiColumnComboBox.EditorControl.BindingContext = new System.Windows.Forms.BindingContext();
multiColumnComboBox.DataSource = table1;
multiColumnComboBox.DisplayMember = "ContactName";

0 comments