I am using the DevExpress 9.3 CheckedComboBoxEdit, and I need to get the collection of all checked items. It seems like this should be a simple task, but the closest thing I have found to a solution is something that says I can use:
CheckedComboBoxEdit.Properties.GetItems.GetCheckedValues()
Unfortunately, there is no GetCheckedValues method here. I have found the following:
CheckedComboBoxEdit.Properties.GetCheckedItems()
which returns an object, but I cannot find any reference on what I should cast the object as. I have also tried to iterate through the items, and check each one to see if it is checked, following the suggestion from here, but Items returns a collection of Strings, not CheckedListBoxItem, so I cannot test if they are checked.
What I want is a String collection of checked items; right now, I am okay to receive them as any type of collection, or even create the collection myself. I know there must be some very simple thing that I am overlooking, but I can't seem to find it.
SOLUTION
This is the solution that I came up with. I would prefer something more elegant; it seems like there should be a way to get the checked items, since this is what the control is for. Nevertheless, 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 anyone can give me a proper solution, I would love to see it.
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 CheckedListBoxItem
which will return only checked items values.
(It's C#, not VB, but the concept is the same.)
I know this is an old post, but I thought I should pitch in anyway.
I'm not sure on when v9.3 was released, but there definitely is a GetCheckedValues() function now. It is described here:
https://documentation.devexpress.com/#WindowsForms/DevExpressXtraEditorsControlsCheckedListBoxItemCollection_GetCheckedValuestopic
and I also found it as the answer in one of their support cases (which is much older than this post) here:
https://www.devexpress.com/Support/Center/Question/Details/Q431364
So to get a list of all the selected values you need something like:
myCombo.Properties.GetItems().GetCheckedValues()
or to check if a specific value was selected:
if (myCombo.Properties.GetItems().GetCheckedValues().contains("myvalue"))
I hope this helps future searchers.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With