Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
50
Add custom multiselect combobox control to UltraWinGrid control
posted

Hi,

I'm trying to develop a sort of dynamic property editor using the UltraWinGrid.
I've got some types working like text, bool, date.

However I'm stuck with a multiselect combobox.

I've implemented it using the ControlContainerEditor class (see atached code)
I'm creating multiselect dropdown boxes and assigning them to the RenderingControl and EditingControl properties of the above class.

However, as you can see in the attached example, when I set a property to a list of integers the editing control shows things like i expect, but the renderingcontrol is still blank.
You can see it in the attached code: when you see the right cell in the line with PropMultiSelectListEditor it is blank. However, the moment you click on this cell (and thus swithc to the editor) you can see teh selected values sepreated by ";" as one expects.
Why is this not correctly rendered in the rendering control and what can be done to have it behave nicely?

We are using the 16.1 version of the controls (16.1.20161.2033)

Thanks,

Serge3531.TestApplicationForInfragistics.zip

Parents
No Data
Reply
  • 467710
    Verified Answer
    Offline posted

    Hi Serge,

    First, I just want to let you know that it looks like you posted this same question twice. So I delete the other post and I will answer your question here.

    I took a look at your sample, and the problem is that the UltraComboEditor you are using for your RenderingControl has no items in it. You are setting the DataSource on it, but since this control never gets parented to any form, it has no BindingContext and so it can't get any data.

    The EditingControl gets parented to the form when you go into edit mode on the cell, so it does not have the same problem. But the RenderingControl never has a parent, and it needs a BindingContext in order to be able to properly get bound data.

    The good news is that this is very easy to solve. All you have to do is either parent this control to something, or else just give it a BindingContext explicitly.

    So you could update your CreateEditor method like so:

                    listEditor.BindingContext = this.BindingContext;
                    listEditor.DataSource = allowedItems;
                    listEditor.ValueMember = "Id";
                    listEditor.DisplayMember = "Name";

    Note that first line of that code, which is the line I added, which sets the BindingContext.

    That would probably be fine, but something else you might want to consider is that if you create controls in code like you are doing here, these controls will never get disposed for the lifetime of your application - unless you explicitly dispose them. This may not be an issue for you. If this your application only creates one instance of the DynamicFilterGridControl and one form, then it doesn't matter. But if you are creating more than one of these controls or showing/closing multiple forms, you could end up leaking memory.

    So rather than setting a BindingContext explicitly, you might be better off simply parenting any controls you create in code to the control. This will provide a BindingContext implicitly, thus solving the problem of the RenderingControl not showing the text, and it also means that the DynamicFilterGridControl's Dispose method will clean up these controls.

                    this.Controls.Add(listEditor);
                    listEditor.Location = new System.Drawing.Point(int.MinValue, int.MinValue);
                    listEditor.DataSource = allowedItems;
                    listEditor.ValueMember = "Id";
                    listEditor.DisplayMember = "Name";
                    

    I set the Location here so that the control is off-screen, just to be on the safe side. But I don't think you actually NEED that code, since the ControlContainerEditor automatically hides these controls from view for you.

Children