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
785
Embed custom controls
posted

Hi, team

I have a question about embed custom controls. And here it is:

I got a custom control CCalendarCombo which inherits from UserControl. It shows in screenshot one.

    public partial class CCalendarCombo : UserControl
    {
      
        public CCalendarCombo()
        {
            InitializeComponent();
            this.commTextEditor.ContextMenuStrip = new ContextMenuStrip();
            this.commTextEditor.ContextMenuStrip.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {
            this.back,
            this.cut,
            this.copy,
            this.past,
            this.del,
            this.selAll});
            this.commTextEditor.AlwaysInEditMode = true;
            this.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(228)))), ((int)(((byte)(237)))), ((int)(((byte)(241)))));
        }
        #endregion
        }

When I read about this ariticle below, I realized that I need to use ControlContainerEditor.

http://help.infragistics.com/Help/Doc/WinForms/2012.2/CLR4.0/HTML/WinControlContainerEditor_Embed_Any_Control_within_WinGrid_Cell_using_ControlContainerEditor_Object.html

And here is what the ControlContainerEditor source.

namespace BaseControl
{
    public partial class CEditor  : ControlContainerEditor 
    {
        private CCalendarCombo cCalendarCombo;
        public CEditor(CCalendarCombo ccb)
        {
            this.cCalendarCombo = ccb;
            this.EditingControl = ccb;
        }
        protected override object RendererValue
        {
            get
            {
                return this.cCalendarCombo.value;
            }
            set
            {
                this.cCalendarCombo.value = (string)value;
            }
        }
    }
}

In Form1, I used it like this(which is used in the winGrid):

CEditor editor = new CEditor(this.cCalendarCombo1);
columns[OUTCOMEDATE].Editor = editor;
columns[OUTCOMEDATE].Width = 200;

But what it implements is like the screenshot below.

In the second one, I want to click the button to show the calender, but it gives no response.

And the third one, when I input some date value in the controls, it doesn't show the value.

Last one, when focus in the controls it shows the value but when left focus it just like the second one.

Any idea how did this happen? Hopefully you'll help me with that.

Thanks for your concern.

Parents
  • 23930
    Offline posted

    Hi Richard,

    Thank you for posting in our forums.

    If you want to use a UserControl in an UltraControlContainerEditor you need to define a property in the UserControl, which is used by the cell to get and set its value. You will also need to implement the INotifyPropertyChanged interface to notify the grid that a value has been changed.

    Also in your case why do you need a custom user control? UltraCalendarCombo implements IProvidesEmbedableEditor interface so you can use it as a grid editor without needing the additional code to set up control an UltraControlContainerEditor.
    I have attached a sample which demonstrates this approach.

    Please let me know if you have any additional questions.

    WG_EmbedUserControl.zip
Reply Children