Back to Devexpress

BaseCheckedListBoxControl.ReadOnly Property

windowsforms-devexpress-dot-xtraeditors-dot-basecheckedlistboxcontrol-d4607177.md

latest2.6 KB
Original Source

BaseCheckedListBoxControl.ReadOnly Property

Gets or sets whether or not users can check or uncheck control items. Items remain selectable even when the ReadOnly property is set to true.

Namespace : DevExpress.XtraEditors

Assembly : DevExpress.XtraEditors.v25.2.dll

NuGet Package : DevExpress.Win.Navigation

Declaration

csharp
[DefaultValue(false)]
[DXCategory("Behavior")]
public bool ReadOnly { get; set; }
vb
<DefaultValue(False)>
<DXCategory("Behavior")>
Public Property [ReadOnly] As Boolean

Property Value

TypeDefaultDescription
Booleanfalse

Specifies whether users are allowed to check and uncheck items.

|

Remarks

Enable the ReadOnly property to prevent users from changing selected states for all the control items. Items remain selectable, which is the main difference from the Enabled setting - if you set this property to false, the entire control deactivates.

Instead of keeping all control items in their current check states, you can handle the BaseCheckedListBoxControl.ItemChecking event and cancel specific state changes. For example, the code sample below does not allow users to select more than three items.

csharp
private void CheckedListBoxControl1_ItemChecking(object sender, ItemCheckingEventArgs e)
{
    CheckedListBoxControl control = sender as CheckedListBoxControl;
    if (control.CheckedItems.Count == 3 && e.NewValue == CheckState.Checked)
        e.Cancel = true;
}
vb
Private Sub CheckedListBoxControl1_ItemChecking(ByVal sender As Object, ByVal e As ItemCheckingEventArgs)
    Dim control As CheckedListBoxControl = TryCast(sender, CheckedListBoxControl)
    If control.CheckedItems.Count = 3 AndAlso e.NewValue = CheckState.Checked Then
        e.Cancel = True
    End If
End Sub

See Also

BaseCheckedListBoxControl Class

BaseCheckedListBoxControl Members

DevExpress.XtraEditors Namespace