Get checked items in DevExpress CheckedComboBoxEdit

I am using DevExpress 9.3 CheckedComboBoxEdit and I need to get a collection of all checked items. It seems like this should be a simple task, but the closest thing I found to solve is what I can use:

CheckedComboBoxEdit.Properties.GetItems.GetCheckedValues()

Unfortunately, there is no GetCheckedValues ​​method here. I found the following:

CheckedComboBoxEdit.Properties.GetCheckedItems()

which returns an object, but I cannot find any reference to what I should use as an object. I also tried iterating over the elements and checking each one to see if it was checked by following the suggestion here , but Items returns a collection of strings, not CheckedListBoxItem, so I can't check if they are checked.

What I want is a String collection of checked items; right now, I can get them as a collection of any type, or even create a collection myself. I know that there must be some very simple thing that I am missing, but I cannot find it.

Decision

This is the solution I came across. I would prefer something more elegant; there seems to be a way to get tested items, as that is what control is needed for. However, this seems to work:

Private Function GetChecked() As List(Of String)
    Dim checked As New List(Of String)
    Dim checkedString As String = CType(SitePickerControl.Properties.GetCheckedItems(), String)
    If (checkedString.Length > 0) Then
        checked.AddRange(checkedString.Split(New Char() {","c}))
    End If
    Return checked
End Function

If someone can give me the right solution, I would love to see him.

+4
source share
2 answers

This is what I use:

var ids = (from CheckedListBoxItem item in checkedComboBoxEdit.Properties.Items
           where item.CheckState == CheckState.Checked
           select (int)item.Value).ToArray();

You can also make an extension method on CheckedListBoxItemthat will only return the marked values ​​of the elements.

( #, VB, .)

+6

, , , .

, v9.3, GetCheckedValues ​​(). :

https://documentation.devexpress.com/#WindowsForms/DevExpressXtraEditorsControlsCheckedListBoxItemCollection_GetCheckedValuestopic

( ):

https://www.devexpress.com/Support/Center/Question/Details/Q431364

, , - :

myCombo.Properties.GetItems().GetCheckedValues()

, :

if (myCombo.Properties.GetItems().GetCheckedValues().contains("myvalue"))

, .

+2

Source: https://habr.com/ru/post/1529460/


All Articles