6

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.

Tim
  • 2,731
  • 9
  • 35
  • 72
  • Do you mean the [windows forms DevExpress control CheckedComboBoxEdit](https://documentation.devexpress.com/#WindowsForms/clsDevExpressXtraEditorsCheckedComboBoxEdittopic)? – surfmuggle Feb 28 '14 at 19:53
  • @threeFourOneSixOneThree: That's the one I am using. I've come across that page several times while looking for a solution, but didn't see anything relating to getting the checked values. – Tim Feb 28 '14 at 20:12
  • In newer versions there is a SelectedItems collection that gives you back all the checked items. I assume 9.3 does not have that? Perhaps it is specific to the developement environment. Is this Winforms, WPF, Silverlight... – Steve Feb 28 '14 at 23:35
  • @Steve: I searched for SelectedItems under SitePickerControl, .Properties, and .Items, but it didn't show up in this version. This is a Winforms application. I just don't see how they could release without adding an accessor for the selected items. – Tim Feb 28 '14 at 23:42
  • Sorry, I checked and the CheckedComboEdit does NOT have that, it was the CheckedListBox I was thinking of. Don't see why they would be any different??? – Steve Mar 03 '14 at 15:10

4 Answers4

11

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.)

bpiec
  • 1,561
  • 3
  • 23
  • 38
  • This looks similar to what I eventually wound up doing, and since it is the first "answer", I'll accept it. I hope this provides help for someone in the future. Thank you for the response. – Tim Mar 18 '14 at 12:54
3

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.

Human Wannabe
  • 164
  • 2
  • 10
0

For VB.NET

Dim ids = (From item In checkedComboBoxEdit.Properties.Items Where item.CheckState = CheckState.Checked Select CInt(item.Value)).ToArray()
Slava Rozhnev
  • 9,510
  • 6
  • 23
  • 39
0

This is what I use:

var ids = (checkedComboBoxEdit1.Properties.Items.Where(m => m.CheckState == CheckState.Checked)).Select(m => m.Value).ToArray();
Tomerikoo
  • 18,379
  • 16
  • 47
  • 61