Virtual Grid Check Box Editor

3 posts, 0 answers
  1. Saji
    Saji avatar
    13 posts
    Member since:
    Mar 2016

    Posted 08 Dec 2016 Link to this post

    Hi Telerik,

    I noticed that, there is no "VirtualGridCheckBoxEditor" class. Not sure why. So I decided to create a check box editor by following Telerik's documented approach. See the code below which is my checkbox editor. However, the checkbox, when the cell is in edit stage, is not rendered at the center of the cell element (see attachment checkboxeditornotcenter.png).

    Please assist.

    Thank you,

    Saj.

     

    ------------------------Code--------------------------------------------------------------

        public class CoreVirtualGridCheckBoxEditor : BaseVirtualGridEditor
        {
            protected override Telerik.WinControls.RadElement CreateEditorElement()
            {
                var elmnt = new RadCheckBoxElement();
                return elmnt;
            }
            public override void Initialize(object owner, object value)
            {
                base.Initialize(owner, value);
            }
            public override void BeginEdit()
            {
                base.BeginEdit();
            }
            public override Type DataType
            {
                get
                {
                    return typeof(bool);
                }
            }
            public override object Value
            {
                get
                {
                    RadCheckBoxElement editor = this.EditorElement as RadCheckBoxElement;
                    if (editor.CheckState== System.Windows.Forms.CheckState.Checked)
                    {
                        return true;
                    }
                    return false;
                }
                set
                {
                    RadCheckBoxElement editor = this.EditorElement as RadCheckBoxElement;
                    if (value == null || value.GetType() != typeof(bool))
                    {
                        editor.CheckState = System.Windows.Forms.CheckState.Unchecked;
                        return;
                    }
                    bool val = (bool)value;
                    editor.CheckState = val ? System.Windows.Forms.CheckState.Checked : System.Windows.Forms.CheckState.Unchecked;
                }
            }
        }

  2. Hristo
    Admin
    Hristo avatar
    1504 posts

    Posted 09 Dec 2016 Link to this post

    Hi Saji,

    Thank you for writing.

    In the custom editor class, you need to specify the CheckAlignment property of the editor element. Please see below: 
    public class CoreVirtualGridCheckBoxEditor : BaseVirtualGridEditor
    {
        protected override Telerik.WinControls.RadElement CreateEditorElement()
        {
            var elmnt = new RadCheckBoxElement();
            return elmnt;
        }
        public override void Initialize(object owner, object value)
        {
            base.Initialize(owner, value);
        }
        public override void BeginEdit()
        {
            base.BeginEdit();
        }
        public override Type DataType
        {
            get
            {
                return typeof(bool);
            }
        }
        public override object Value
        {
            get
            {
                RadCheckBoxElement editor = this.EditorElement as RadCheckBoxElement;
                if (editor.CheckState == System.Windows.Forms.CheckState.Checked)
                {
                    return true;
                }
                return false;
            }
            set
            {
                RadCheckBoxElement editor = this.EditorElement as RadCheckBoxElement;
                editor.CheckAlignment = ContentAlignment.MiddleCenter;
                if (value == null || value.GetType() != typeof(bool))
                {
                    editor.CheckState = System.Windows.Forms.CheckState.Unchecked;
                    return;
                }
                bool val = (bool)value;
                editor.CheckState = val ? System.Windows.Forms.CheckState.Checked : System.Windows.Forms.CheckState.Unchecked;
            }
        }
    }

    I hope this helps. Should you have further questions please do not hesitate to write back.

    Regards,
    Hristo
    Telerik by Progress
    Telerik UI for WinForms is ready for Visual Studio 2017 RC! Learn more.
  3. Saji
    Saji avatar
    13 posts
    Member since:
    Mar 2016

    Posted 09 Dec 2016 in reply to Hristo Link to this post

    Many thanks. Working well.
Back to Top