This is a migrated thread and some comments may be shown as answers.

CheckedListBox.CheckedItemCollection Contains

1 Answer 200 Views
CheckedListBox
This is a migrated thread and some comments may be shown as answers.
Tarık
Top achievements
Rank 1
Tarık asked on 27 Mar 2017, 01:34 PM

hi,

i have some code like this

For i = 0 To count
    Dim col1 As CheckedListBox.CheckedItemCollection = chk_Sorumlular.CheckedItems
    Dim col2 As CheckedListBox.CheckedItemCollection = chk_Beyannameler.CheckedItems
    If col1.Contains(Me.Izgara.Rows(i).Cells(Me.sutun_sorumlu.Name).Value) And col2.Contains(Me.Izgara.Rows(i).Cells(Me.sutun_Turu.Name).Value) Then
        Dim str As String = Me.Izgara.Rows(i).Cells(Me.sutun_ID.Name).Value.ToString()
        Dim chrArray() As Char = {"|"c}
        If (Microsoft.VisualBasic.CompilerServices.Operators.CompareString(str.Split(chrArray)(1).Trim(), "", False) <> 0) And chk_TahakkukFisi.Checked Then
            Me.Izgara.Rows(i).Cells(Me.sutun_Sec_Tahakkuk.Name).Value = CheckState.Checked
        Else
            Me.Izgara.Rows(i).Cells(Me.sutun_Sec_Tahakkuk.Name).Value = CheckState.Unchecked
 
        End If
        If (Microsoft.VisualBasic.CompilerServices.Operators.CompareString(str.Split(chrArray)(0).Trim(), "", False) <> 0) And chk_Beyanname.Checked Then
            Me.Izgara.Rows(i).Cells(Me.sutun_Sec_Beyanname.Name).Value = CheckState.Checked
        Else
            Me.Izgara.Rows(i).Cells(Me.sutun_Sec_Beyanname.Name).Value = CheckState.Unchecked
 
        End If
    Else
        Me.Izgara.Rows(i).Cells(Me.sutun_Sec_Tahakkuk.Name).Value = CheckState.Unchecked
        Me.Izgara.Rows(i).Cells(Me.sutun_Sec_Beyanname.Name).Value = CheckState.Unchecked
    End If
    Application.DoEvents()
Next

 

i can do this with microsoft checkedlistbox component

but i try do with radcheckedlistbox and get error

An unhandled exception of type 'System.InvalidCastException' occurred in asd.exe
Additional information: An object of type 'System.String' could not be thrown to 'Telerik.WinControls.UI.ListViewDataItem'.

 

how can i fix this

 

thank you

 

1 Answer, 1 is accepted

Sort by
0
Accepted
Dimitar
Telerik team
answered on 28 Mar 2017, 07:54 AM
Hello Tarik,

Which is the exact line where this exception occurs? If it is when you are calling the Contains method here is how you can create your own method that checks if an item with particular text is checked:
Private Sub radButton1_Click(ByVal sender As Object, ByVal e As EventArgs)
    Dim res = ContainsItem(radCheckedListBox1.CheckedItems, "ListViewItem 5")
End Sub
Public Function ContainsItem(ByVal items As ListViewCheckedItemCollection, ByVal text As String) As Boolean
    For Each item As ListViewDataItem In items
        If item.Text = text Then
            Return True
 
        End If
    Next item
    Return False
End Function

I hope this will be useful. Let me know if you have additional questions.

Regards,
Dimitar
Telerik by Progress
Try our brand new, jQuery-free Angular 2 components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
Tags
CheckedListBox
Asked by
Tarık
Top achievements
Rank 1
Answers by
Dimitar
Telerik team
Share this question
or