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

Virtual Grid Check Box Editor

2 Answers 75 Views
VirtualGrid
This is a migrated thread and some comments may be shown as answers.
Saji
Top achievements
Rank 1
Saji asked on 08 Dec 2016, 07:57 PM

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 Answers, 1 is accepted

Sort by
0
Hristo
Telerik team
answered on 09 Dec 2016, 12:13 PM
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.
0
Saji
Top achievements
Rank 1
answered on 09 Dec 2016, 04:32 PM
Many thanks. Working well.
Tags
VirtualGrid
Asked by
Saji
Top achievements
Rank 1
Answers by
Hristo
Telerik team
Saji
Top achievements
Rank 1
Share this question
or