MultiColumnComboBox Editor in PropertyGrid

5 posts, 1 answers
  1. Randy
    Randy avatar
    19 posts
    Member since:
    Oct 2012

    Posted 24 Oct 2012 Link to this post

    Is there a way to use a multicolumn combo box editor in the PropertyGrid?

    I've tried creating my own custom editor inheriting from the RadMultiColumnComboBoxElement, but I can't seem to get it working correctly.

    Thanks
  2. Answer
    Tom Mieck
    Tom Mieck avatar
    11 posts
    Member since:
    Aug 2012

    Posted 27 Oct 2012 Link to this post

    Hi,
    Please find the code below

    public class MultyColumnComboBoxEditor : BaseInputEditor
        {


            public RadGridView Grid
            {
                get
                {
                    return ((RadMultiColumnComboBoxElement)this.EditorElement).EditorControl;
                }
            }
            public override object Value
            {
                get
                {
                    return ((RadMultiColumnComboBoxElement)this.EditorElement).SelectedValue;
                }
                set
                {
                    ((RadMultiColumnComboBoxElement)this.EditorElement).SelectedValue = value;
                }
            }


            public override void BeginEdit()
            {
                base.BeginEdit();


                this.EditorElement.Focus();
                ((RadMultiColumnComboBoxElement)this.EditorElement).SelectedValueChanged += new EventHandler(MultyColumnComboBoxEditor_SelectedValueChanged);
            }


            public object DataSource
            {
                get
                {
                    return ((RadMultiColumnComboBoxElement)this.EditorElement).DataSource;
                }
                set
                {
                    ((RadMultiColumnComboBoxElement)this.EditorElement).DataSource = value;
                }
            }


            public string DisplayMember
            {
                get
                {
                    return ((RadMultiColumnComboBoxElement)this.EditorElement).DisplayMember;
                }
                set
                {
                    ((RadMultiColumnComboBoxElement)this.EditorElement).DisplayMember = value;
                }
            }
            public bool AutoFilter
            {
                get
                {
                    return ((RadMultiColumnComboBoxElement)this.EditorElement).AutoFilter;
                }
                set
                {
                    ((RadMultiColumnComboBoxElement)this.EditorElement).AutoFilter = true;
                    ((RadMultiColumnComboBoxElement)this.EditorElement).AutoFilter = value;
                }
            }
            public string ValueMember
            {
                get
                {
                    return ((RadMultiColumnComboBoxElement)this.EditorElement).ValueMember;
                }
                set
                {
                    ((RadMultiColumnComboBoxElement)this.EditorElement).ValueMember = value;
                }
            }


            void MultyColumnComboBoxEditor_SelectedValueChanged(object sender, EventArgs e)
            {
                this.OnValueChanged();
            }


            public override bool EndEdit()
            {
                ((RadMultiColumnComboBoxElement)this.EditorElement).SelectedValueChanged -= new EventHandler(MultyColumnComboBoxEditor_SelectedValueChanged);
                return base.EndEdit();
            }


            protected override RadElement CreateEditorElement()
            {
                RadMultiColumnComboBoxElement mccb = new RadMultiColumnComboBoxElement();
                if (mccb.MultiColumnPopupForm.BindingContext == null)
                {
                    mccb.MultiColumnPopupForm.BindingContext = new BindingContext();
                }


                return mccb;
            }


            public override Type DataType
            {
                get { return typeof(string); }
            }
        }


    put this code in the editorrequired event in the propertygrid
     void radPropertyGrid1_EditorRequired(object sender, PropertyGridEditorRequiredEventArgs e)
            {
    MultyColumnComboBoxEditor mccb = new MultyColumnComboBoxEditor();
                   
                    e.EditorType = typeof(MultyColumnComboBoxEditor);
                  
    datatable employee= getdata();


                    mccb.DisplayMember = "Name";
                    mccb.ValueMember = "ID";
                    mccb.DataSource = employee
    ;
                    e.Editor = mccb;
                    
                    mccb.AutoFilter = true;
    }

    let me know if u have any other questions
  3. UI for WinForms is Visual Studio 2017 Ready
  4. Randy
    Randy avatar
    19 posts
    Member since:
    Oct 2012

    Posted 29 Oct 2012 Link to this post

    Thanks, that was exactly what I needed!
  5. Ivan Petrov
    Admin
    Ivan Petrov avatar
    701 posts

    Posted 29 Oct 2012 Link to this post

    Hello Tom and Randy,

    Thank you both for writing.

    Tom's solution is exactly the way to go in the situation. 

    If you have further questions, do not hesitate to write back.
     
    Kind regards,
    Ivan Petrov
    the Telerik team
    Q3’11 of RadControls for WinForms is available for download (see what's new). Get it today.
  6. Tom Mieck
    Tom Mieck avatar
    11 posts
    Member since:
    Aug 2012

    Posted 31 Oct 2012 Link to this post

    Hi randy,
    I have one question,please help me out.
    In propertygrid , when user  expand and collapse one category section the order of the items getting dispersed

    lets say i have category1 which contains employee,department fields(----this is the default order am showing)

    order:
    category1:
    employee
    department


    when user clicks on  arrow icon(it will collapse that section,and again click on the same icon ) then items order of the items is changing i.e department,employee

    changed order:
    category1:
    department
    employee


    department coming first, followed by employee  field.

    I dont want that behaviour even when user clicks on  expand and collapse arrow icon
Back to Top
UI for WinForms is Visual Studio 2017 Ready