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

RadPopUpEditor

4 Answers 168 Views
PopupEditor
This is a migrated thread and some comments may be shown as answers.
Daniel
Top achievements
Rank 2
Daniel asked on 08 Sep 2015, 08:39 AM
I wanted to use RadPopupEditor with a gridview as an associated Control to implement a multiselectmultiColumncombobox.

In Design time, my User Control has a radPopUpEditor and a gridview. I am trying to set the value of radPopUpEditor.AssociatedControl within the property window when an exception occurs saying "Error using the dropdown: Unable to cast object of type 'System.Windows.Forms.UserControl' to type 'System.Windows.Forms.Form'".

I did the same on a form with the same controls (a radPopUpEditor and a radgridview).
Though No Error exception occurs, the gridview is not available choice in the AssociatedControl Property.

With this, I have two questions.

1. Is it possible to use radPopUpEditor within a User Control? 
2. what type of controls can I use to as RadPopupEditor.AssociatedControl?

4 Answers, 1 is accepted

Sort by
0
Dimitar
Telerik team
answered on 08 Sep 2015, 09:59 AM
Hi Daniel,

Thank you for contacting us.

Yes, you can use RadPopupEditor within a user control. You can only associate the control with RadPopupContainer. Please note that you can put any controls in the RadPopupContainer. Detailed information about this is available here:
I hope this helps. Should you have any other questions do not hesitate to ask.

Regards,
Dimitar
Telerik

0
Abbas
Top achievements
Rank 1
answered on 09 Jan 2018, 07:20 AM
Hi Dimitar,

I will be very grateful if you show me how to use RadPopupEditor in Radgridview as a custom element inside a cell.
I need a code snippet.

Regards,
Thanks.
0
Dess | Tech Support Engineer, Principal
Telerik team
answered on 09 Jan 2018, 12:04 PM
Hello, Abbas, 

Thank you for writing back. 

I would like to note that using controls in grid cells may slow down the scrolling and will cause visual glitches as they do not support clipping. The recommended approach is to use a custom editor which can be activated for the respective cell. Here is a sample code snippet demonstrating how to use a custom editor with RadPopupEditor hosting a RadGridView.



public RadForm1()
{
    InitializeComponent();
    this.radGridView1.EditorRequired += radGridView1_EditorRequired;
    this.radGridView1.Columns.Add("MyColumn");
}
 
private void radGridView1_EditorRequired(object sender, EditorRequiredEventArgs e)
{
    if (this.radGridView1.CurrentColumn.Name == "MyColumn")
    {
        MyEditor editor = new MyEditor();
        editor.DataSource = this.categoriesBindingSource;
        editor.DisplayMember = "CategoryName";
        e.Editor = editor;
    }
}
 
public class MyEditor : BaseGridEditor
{
    public string DisplayMember { get; set; }
 
    public object DataSource
    {
        get
        {
            {
                return this.grid.DataSource;
            }
        }
        set
        {
            this.grid.DataSource = value;
        }
    }
 
    public override void BeginEdit()
    {
        base.BeginEdit();
        this.popupEditor.TextBoxElement.TextBoxItem.TextBoxControl.Focus();
    }
 
    public override object Value
    {
        get
        {
            if (grid.CurrentRow != null)
            {
                return this.grid.CurrentRow.Cells[this.DisplayMember].Value;
            }
            return null;
        }
        set
        {
            if (value != null)
            {
                foreach (GridViewRowInfo row in grid.Rows)
                {
                    if (row.Cells[this.DisplayMember].Value == value)
                    {
                        grid.CurrentRow = row;
                        break;
                    }
                }
            }
        }
    }
 
    RadGridView grid = new RadGridView();
    RadPopupEditor popupEditor = new RadPopupEditor();
    RadPopupContainer container = new RadPopupContainer();
 
    protected override RadElement CreateEditorElement()
    {
        popupEditor.AssociatedControl = container;
        popupEditor.DropDownStyle = RadDropDownStyle.DropDown;
        container.Controls.Add(grid);
        grid.Dock = DockStyle.Fill;
        grid.EnableFiltering = true;
        grid.ShowFilteringRow = false;
        grid.ReadOnly = true;
        grid.EnableCustomFiltering = true;
        grid.AutoSizeColumnsMode = GridViewAutoSizeColumnsMode.Fill;
        grid.CustomFiltering += grid_CustomFiltering;
        this.popupEditor.TextBoxElement.TextChanged += popupEditor_TextChanged;
 
        RadHostItem item = new RadHostItem(popupEditor);
        return item;
    }
 
    private void popupEditor_TextChanged(object sender, EventArgs e)
    {
        grid.MasterTemplate.Refresh();
        popupEditor.PopupEditorElement.ShowPopup();
        this.popupEditor.PopupEditorElement.TextBoxElement.TextBoxItem.TextBoxControl.Focus();
    }
 
    private void grid_CustomFiltering(object sender, GridViewCustomFilteringEventArgs e)
    {
        string searchText = popupEditor.Text;
        if (searchText != null && searchText != string.Empty)
        {
            DataRowView rowView = e.Row.DataBoundItem as DataRowView;
            e.Handled = true;
            e.Visible = rowView.Row[this.DisplayMember].ToString().Contains(searchText);
        }
        else
        {
            e.Handled = false;
        }
    }
}

Note that by default GridViewMultiComboBoxColumn provides a similar functionality. But with RadPopupEditor you can control the editor's behavior according to your custom requirement.

I hope this information helps. If you have any additional questions, please let me know. 

 Regards,
Dess
Progress Telerik
Try our brand new, jQuery-free Angular components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
0
Abbas
Top achievements
Rank 1
answered on 10 Jan 2018, 12:22 PM
Thank you so much .
Tags
PopupEditor
Asked by
Daniel
Top achievements
Rank 2
Answers by
Dimitar
Telerik team
Abbas
Top achievements
Rank 1
Dess | Tech Support Engineer, Principal
Telerik team
Share this question
or