Three State checkboxes and events

3 posts, 0 answers
  1. Michal
    Michal avatar
    4 posts
    Member since:
    Sep 2011

    Posted 08 Sep 2011 Link to this post

    I am working on an application that uses grid view with checkboxes. When checkbox value is changed, it calls ValueChanged event with radGridView.EndEdit() and then calls CellValueChanged to read new data.

    I want to expand checkboxes functionality with Three State mode however I want user only to be able to switch between normal On and Off states, while the Indeterminate state can only be assigned from the code. I want to make it so user can either go   On -> Off,   On  -> Off  or Indeterminate -> Off, and not On -> Indeterminate . 

    The thing is, I can't find a right event, that should be called when checkbox value is changed and change it, so user cannot reach null state by clicking it. Normally, in Three State mode, when user clicks on checkbox in On state, Indeterminate state is called. I want to switch this state to Off  before reading the data.

    I hope I've explained my problem clearly enough. Thank you for reading my post :)

  2. Emanuel Varga
    Emanuel Varga avatar
    1336 posts
    Member since:
    May 2010

    Posted 09 Sep 2011 Link to this post

    Hello Michal,

    Just register for the DataBindingComplete event and set the checkbox column to the three state mode, like so:
    void radGridView1_DataBindingComplete(object sender, GridViewBindingCompleteEventArgs e)
        var checkBoxColumn = radGridView1.Columns[2] as GridViewCheckBoxColumn;
        if (checkBoxColumn != null)
            checkBoxColumn.ThreeState = true;

    Or if you are creating the columns manually just set that property on the column directly.

    Hope this helps, if you have any other questions please let me know,

    Best Regards,
    Emanuel Varga

    WinForms MVP
  3. Svett
    Svett avatar
    728 posts

    Posted 13 Sep 2011 Link to this post

    Hello Michal,

    You can use the ThreeState mode of the GridViewCheckBoxColumn as Emanuel mentioned. In addition to his suggestion, you can handle the ValueChanged event to achieve the desired behavior:
    private bool isValueChanging = false;
    private void radGridView1_ValueChanged(object sender, EventArgs e)
        if (isValueChanging)
        RadCheckBoxEditor checkBoxEditor = sender as RadCheckBoxEditor;
        ToggleState state = (ToggleState)checkBoxEditor.Value;
        if (checkBoxEditor != null && state == ToggleState.Indeterminate)
            isValueChanging = true;
            checkBoxEditor.Value = ToggleState.Off;
            isValueChanging = false;
    protected override void OnLoad(EventArgs e)
        this.radGridView1.DataSource = Data.GetDummyEmployees();
        GridViewCheckBoxColumn checkBoxColumn = this.radGridView1.Columns["SelfEmployeed"] as GridViewCheckBoxColumn;
        checkBoxColumn.ThreeState = true;

    I hope this helps.
    the Telerik team

    Thank you for being the most amazing .NET community! Your unfailing support is what helps us charge forward! We'd appreciate your vote for Telerik in this year's DevProConnections Awards. We are competing in mind-blowing 20 categories and every vote counts! VOTE for Telerik NOW >>

Back to Top