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

MultiColumnComboBox Editor in PropertyGrid

4 Answers 162 Views
PropertyGrid
This is a migrated thread and some comments may be shown as answers.
Randy
Top achievements
Rank 1
Randy asked on 24 Oct 2012, 07:51 PM
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

4 Answers, 1 is accepted

Sort by
0
Accepted
Tom Mieck
Top achievements
Rank 1
answered on 27 Oct 2012, 05:03 AM
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
0
Randy
Top achievements
Rank 1
answered on 29 Oct 2012, 01:03 PM
Thanks, that was exactly what I needed!
0
Ivan Petrov
Telerik team
answered on 29 Oct 2012, 03:11 PM
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.
0
Tom Mieck
Top achievements
Rank 1
answered on 31 Oct 2012, 03:54 PM
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
Tags
PropertyGrid
Asked by
Randy
Top achievements
Rank 1
Answers by
Tom Mieck
Top achievements
Rank 1
Randy
Top achievements
Rank 1
Ivan Petrov
Telerik team
Share this question
or