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

RadCheckBoxEditor ThreeState not maintaining Indeterminate when displaying the check box

3 Answers 146 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Andrew
Top achievements
Rank 1
Andrew asked on 16 May 2016, 03:03 PM

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

 

3 Answers, 1 is accepted

Sort by
0
Accepted
Dimitar
Telerik team
answered on 17 May 2016, 10:23 AM
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.
0
Andrew
Top achievements
Rank 1
answered on 17 May 2016, 11:20 AM

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.

0
Dimitar
Telerik team
answered on 18 May 2016, 07:24 AM
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.
Tags
GridView
Asked by
Andrew
Top achievements
Rank 1
Answers by
Dimitar
Telerik team
Andrew
Top achievements
Rank 1
Share this question
or