RadCheckBoxEditor ThreeState not maintaining Indeterminate when displaying the check box

4 posts, 1 answers
  1. Andrew
    Andrew avatar
    3 posts
    Member since:
    Oct 2010

    Posted 16 May Link to this post

    I have a WinControl RadGridView that is not data-bound to any dataset, we manually create the rows and need be based on certain criteria at the time of load. Clicking into specfic cell, the EditorRequired event get fired where depending on which row we are working with we will present a custom control to fit the needs for that row.

    For one of the conditions we are adding a RadCheckBoxEditor to the cell with ThreeState set to true.

    Values are getting sent back to the grid row correctly for all three states, but when we try to load the editor again, when it trying to load an Indeterminate the check box always renders as off.

    Following the ValueChanged and ValueChanging events; ValueChanged is coming in as Indeterminate, but ValueChanging is showing as false for the new value.  This is before any user interaction.

    Is there anyway for the checkbox to paint as the "Indeterminate" state.

    Thank you

     

  2. Answer
    Dimitar
    Admin
    Dimitar avatar
    1404 posts

    Posted 17 May Link to this post

    Hi Andrew,

    Thank you for writing.

    The editor is not created for such scenario. It will work properly when the data type of the entire column is set. For your scenario, you can create a custom editor. This way you can override the Value property and set the states according to your requirement. For example:
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
            this.radGridView1.Columns.Add(new GridViewTextBoxColumn() );
            radGridView1.Rows.Add(true);
            radGridView1.Rows.AddNew();
            radGridView1.Rows.Add(false);
        }
     
        private void RadGridView1_EditorRequired(object sender, Telerik.WinControls.UI.EditorRequiredEventArgs e)
        {
            MyRadCheckBoxEditor editor = new MyRadCheckBoxEditor();
     
            e.Editor = editor;
        }
     
    }
    class MyRadCheckBoxEditor : BaseGridEditor
    {
        public override object Value
        {
            get
            {
                var element = (RadCheckBoxElement)this.EditorElement;
             
                if (element.CheckState ==  CheckState.Indeterminate)
                {
                    return null;
                }
                else
                {
                    return element.CheckState == CheckState.Checked;
                }
            }
     
            set
            {
                var element = (RadCheckBoxElement)this.EditorElement;
                if (value == null || value == "")
                {
                    element.CheckState = CheckState.Indeterminate;
                }
                else if (value.ToString() == "True")
                {
                    element.CheckState = CheckState.Checked;
                }
                else
                {
                    element.CheckState = CheckState.Unchecked;
                }
            }
        }
        protected override RadElement CreateEditorElement()
        {
            return new RadCheckBoxElement() { IsThreeState = true , Alignment = ContentAlignment.MiddleCenter, CheckAlignment = ContentAlignment.MiddleCenter};
        }
    }

    I hope this helps. Should you have any other questions do not hesitate to ask.

    Regards,
    Dimitar
    Telerik
    Do you need help with upgrading your AJAX, WPF or WinForms project? Check the Telerik API Analyzer and share your thoughts.
  3. UI for WinForms is Visual Studio 2017 Ready
  4. Andrew
    Andrew avatar
    3 posts
    Member since:
    Oct 2010

    Posted 17 May in reply to Dimitar Link to this post

    Thank you,  I would have presumed that the control would be able to handle having its value set to Indeterminate, and was hoping I was just missing something, but it was looking that I was going to have to do it this way.

     

    Thank you again.

  5. Dimitar
    Admin
    Dimitar avatar
    1404 posts

    Posted 18 May Link to this post

    Hi Andrew,

    Thank you for writing back.

    The default editor can handle the values, but you will need to set the DataType (for tree state checkbox it should be Telerik.WinControls.Enumerations.ToggleState) for the entire column. I don't think that this is suitable for your case and this is why I suggested the custom editor. 

    Do not hesitate to contact us if you have other questions.
     
    Regards,
    Dimitar
    Telerik
    Do you need help with upgrading your AJAX, WPF or WinForms project? Check the Telerik API Analyzer and share your thoughts.
Back to Top