Back to Devexpress

QueryCheckStateByValueEventArgs.Value Property

windowsforms-devexpress-dot-xtraeditors-dot-controls-dot-querycheckstatebyvalueeventargs.md

latest6.4 KB
Original Source

QueryCheckStateByValueEventArgs.Value Property

Gets the current edit value.

Namespace : DevExpress.XtraEditors.Controls

Assembly : DevExpress.XtraEditors.v25.2.dll

NuGet Package : DevExpress.Win.Navigation

Declaration

csharp
public object Value { get; }
vb
Public ReadOnly Property Value As Object

Property Value

TypeDescription
Object

A Object expression representing an editor’s edit value.

|

Example

This example demonstrates how to handle RepositoryItemCheckEdit.QueryCheckStateByValue and RepositoryItemCheckEdit.QueryValueByCheckState events in order to use a check editor to display and modify data from the bound data field.

The example assumes that a check editor is bound to a specific dataset field whose type is not obviously known and should be determined programmatically. The available data types that the field can take on are boolean, string and integer. So the field can contain the following combinations representing an option value (these values will be used to set the editor’s CheckEdit.EditValue property):

  • True , False - for the boolean type;
  • Yes “, “ No “, “ ? “ - for the string type;
  • 1 , 0 , -1 - for the integer type.

It is evident that making use of RepositoryItemCheckEdit.ValueChecked, RepositoryItemCheckEdit.ValueUnchecked and RepositoryItemCheckEdit.ValueGrayed properties is insufficient in this case. Thus, the example requires and implements a custom “edit value -> check state” and “check state -> edit value” conversion logic, which is illustrated by the sample code below.

csharp
using DevExpress.XtraEditors.Controls;

private void checkEdit1_QueryCheckStateByValue(object sender, QueryCheckStateByValueEventArgs e) {
    string val = e.Value.ToString();
    switch (val) {
        case "True":
        case "Yes":
        case "1":
            e.CheckState = CheckState.Checked;
            break;
        case "False":
        case "No":
        case "0":
            e.CheckState = CheckState.Unchecked;
            break;
        default:
            e.CheckState = CheckState.Indeterminate;
            break;
    }
    e.Handled = true;
}

private void checkEdit1_QueryValueByCheckState(object sender, QueryValueByCheckStateEventArgs e) {
    CheckEdit edit = sender as CheckEdit;
    object val = edit.EditValue;
    switch (e.CheckState) {
        case CheckState.Checked:
            if (val is bool) e.Value = true;
            else if (val is string) e.Value = "Yes";
            else if (val is int) e.Value = 1;
            else e.Value = null;
        break;
        case CheckState.Unchecked:
            if (val is bool) e.Value = false;
            else if (val is string) e.Value = "No";
            else if (val is int) e.Value = 0;
            else e.Value = null;
            break;
        default:
            if (val is bool) e.Value = false;
            else if (val is string) e.Value = "?";
            else if (val is int) e.Value = -1;
            else e.Value = null;
            break;
    }
    e.Handled = true;
}
vb
Private Sub QueryCheckStateByValue(ByVal sender As Object, _
  ByVal e As DevExpress.XtraEditors.Controls.QueryCheckStateByValueEventArgs)
    Dim val As String = e.Value.ToString()
    Select Case val
        Case "True", "Yes", "1"
            e.CheckState = CheckState.Checked
        Case "False", "No", "0"
            e.CheckState = CheckState.Unchecked
        Case Else
            e.CheckState = CheckState.Indeterminate
    End Select
    e.Handled = True
End Sub

Private Sub QueryValueByCheckState(ByVal sender As Object, _ 
  ByVal e As DevExpress.XtraEditors.Controls.QueryValueByCheckStateEventArgs)
    Dim Edit As CheckEdit = CType(sender, CheckEdit)
    Dim Val As Object = Edit.EditValue
    Select Case e.CheckState
        Case CheckState.Checked
            If TypeOf Val Is Boolean Then
                e.Value = True
            ElseIf TypeOf Val Is String Then
                e.Value = "Yes"
            ElseIf TypeOf Val Is Integer Then
                e.Value = 1
            Else : e.Value = Nothing
            End If
        Case CheckState.Unchecked
            If TypeOf Val Is Boolean Then
                e.Value = False
            ElseIf TypeOf Val Is String Then
                e.Value = "No"
            ElseIf TypeOf Val Is Integer Then
                e.Value = 0
            Else : e.Value = Nothing
            End If
        Case Else
            If TypeOf Val Is Boolean Then
                e.Value = False
            ElseIf TypeOf Val Is String Then
                e.Value = "?"
            ElseIf TypeOf Val Is Integer Then
                e.Value = -1
            Else : e.Value = Nothing
            End If
    End Select
    e.Handled = True
End Sub

See Also

CheckState

Handled

EditValue

QueryCheckStateByValueEventArgs Class

QueryCheckStateByValueEventArgs Members

DevExpress.XtraEditors.Controls Namespace