Hide

SftTree/NET 2.0 - Tree Control for Windows Forms

Display
Print

State Property, CheckBoxPartClass Class

Defines the checkbox state.

Class: CheckBoxPartClass
Namespace: Softelvdm.Controls
Assembly: Softelvdm.SftTreeNET

Syntax

public CheckBoxStateEnum State { get; set; }
Public Property State As CheckBoxStateEnum

Value

The checkbox state.

The default value is CheckBoxStateEnum.Unchecked.

Comments

Defines the checkbox state.

Examples

C#

        // Handle the space char to select the checkbox or radiobutton
        private void sftTree1_KeyPress(object sender, KeyPressEventArgs e) {
            if (e.KeyChar == ' ') {
                ItemClass item = sftTree1.FocusItem;
                if (item != null) {
                    GenericPartClass gp = item.Cells[0].Parts[0];
                    if (gp is CheckBoxPartClass) {
                        CheckBoxPartClass cb = (CheckBoxPartClass) gp;
                        cb.State = cb.State == CheckBoxStateEnum.Checked ? CheckBoxStateEnum.Unchecked : CheckBoxStateEnum.Checked;
                        e.Handled = true;
                        // changing the checkbox state doesn't automatically call the CheckBoxClicked event
                        CellClass owningCell = (CellClass)cb.PartOwner;
                        ItemClass owningItem = owningCell.OwningItem;
                        sftTree1_CheckBoxClicked(this, new PartEventArgs(owningItem, owningCell, null, cb));
                    } else if (gp is RadioButtonPartClass) {
                        RadioButtonPartClass rb = (RadioButtonPartClass)gp;

VB.NET

Private Sub SftTree1_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles SftTree1.KeyPress
    If e.KeyChar = " " Then
        Dim item As ItemClass = SftTree1.FocusItem
        If Not item Is Nothing Then
            Dim gp As GenericPartClass = item.Cells(0).Parts(0)
            If TypeOf gp Is CheckBoxPartClass Then
                Dim cb As CheckBoxPartClass = gp
                If cb.State = CheckBoxStateEnum.Checked Then
                    cb.State = CheckBoxStateEnum.Unchecked
                Else
                    cb.State = CheckBoxStateEnum.Checked
                End If
                e.Handled = True
                ' changing the checkbox state doesn't automatically call the CheckBoxClicked event
                Dim owningCell As CellClass = cb.PartOwner
                Dim owningItem As ItemClass = owningCell.OwningItem

See Also CheckBoxPartClass Class | Classes | SftTree/NET 2.0