本文介绍了在DevExpress CheckedComboBoxEdit中获取检查项目的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用DevExpress 9.3 CheckedComboBoxEdit,我需要获取所有已检查项目的集合。似乎这应该是一个简单的任务,但是我找到的最接近的一个解决方案是我可以使用的东西:

  CheckedComboBoxEdit.Properties.GetItems.GetCheckedValues()

不幸的是,这里没有GetCheckedValues方法。我已经找到以下内容:

  CheckedComboBoxEdit.Properties.GetCheckedItems()
pre>

它返回一个对象,但我找不到任何关于我应该将对象转换为的引用。我还试图迭代这些项目,并检查每个项目是否检查,按照,但Items返回一个字符串的集合,而不是CheckedListBoxItem,所以我无法测试是否被检查。



我想要什么是已检查项目的String集合;现在,我可以收到他们作为任何类型的收藏,甚至自己创建收藏。我知道我会忽略一些非常简单的事情,但我似乎找不到。



解决方案



这是我想出的解决方案。我更喜欢更优雅的东西似乎应该有一种方式来获得检查的项目,因为这是控件的。然而,这似乎是有效的:

 私有函数GetChecked()作为列表(String)
Dim List(Of String)
Dim checkedString As String = CType(SitePickerControl.Properties.GetCheckedItems(),String)
If(checkedString.Length> 0)然后
checked.AddRange(checkedString。拆分(新的Char(){,c}))
结束If
返回检查
结束函数

如果有人可以给我一个正确的解决方案,我很乐意看到。

解决方案

p>这是我使用的:

  var ids =(来自checkedComboBoxEdit.Properties中的CheckedListBoxItem项.Items 
其中item.CheckState == CheckState.Checked
select(int)item.Value).ToArray();

您还可以在 CheckedListBoxItem



(它是C#,而不是VB,但概念是一样的。)


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

这篇关于在DevExpress CheckedComboBoxEdit中获取检查项目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-20 21:47