Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6105083
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T13:55:00+00:00 2026-05-23T13:55:00+00:00

For a long time, I have been try to do this: Private Sub Search()

  • 0

For a long time, I have been try to do this:

Private Sub Search()
    'DataGrid1.ItemsSource = From k In Globals.Batchs.BatchList Where (CType(k.Category, String).ToLower().Contains(SearchByCategory.Text)) Select k
    Dim tot As List(Of WorkMateLib.BatchLib.BatchItem) = Globals.Batchs.BatchList
    If Not SearchByCategory.Text = "" Then
        tot = From k As WorkMateLib.BatchLib.BatchItem In tot Where CType(k.Category, String).ToLower().Contains(SearchByCategory.Text) Select k
    End If
    If Not SearchByCourse.Text = "" Then
        tot = From k In tot Where (CType(k.CourseName, String).ToLower().Contains(SearchByCourse.Text))
    End If
    If Not SearchByName.Text = "" Then
        tot = From k In tot Where (CType(k.BatchName, String).ToLower().Contains(SearchByName.Text))
    End If
    If Not SearchByYear.Text = "" Then
        tot = From k In tot Where (CType(k.DateStarted, Date).Year.ToString.ToLower.Contains(SearchByYear.Text))
    End If
    DataGrid1.ItemsSource = tot
End Sub

But is keep on throwing the following exception:

Unable to cast object of type 'WhereSelectListIterator`2[WorkMateLib.BatchLib.BatchItem,WorkMateLib.BatchLib.BatchItem]' to type 'System.Collections.Generic.List`1[WorkMateLib.BatchLib.BatchItem]'.

Could you please review and let me know where I am going wrong please.
Following is the code for the classes:

Namespace BatchLib
    Public Class BatchItem
        Dim _BatchID As String
        Dim _BatchName As String
        Dim _Category As String
        Dim _CourseID As String
        Dim _CourseName As String
        Dim _StartDate As Date
        Dim _StartDateFormated As String
        Dim _Deleted As Boolean
#Region "Property"
        Property BatchID
            Get
                Return _BatchID
            End Get
            Set(value)
                _BatchID = value
            End Set
        End Property
        Property BatchName
            Get
                Return _BatchName
            End Get
            Set(value)
                _BatchName = value
            End Set
        End Property
        Property Category
            Get
                Return _Category
            End Get
            Set(value)
                _Category = value
            End Set
        End Property
        Property CourseID
            Get
                Return _CourseID
            End Get
            Set(value)
                _CourseID = value
            End Set
        End Property
        Property DateStarted
            Get
                Return _StartDate
            End Get
            Set(value)
                _StartDate = value
            End Set
        End Property
        Property Deleted
            Get
                Return _Deleted
            End Get
            Set(value)
                _Deleted = value
            End Set
        End Property
        Property CourseName
            Get
                Return _CourseName
            End Get
            Set(value)
                _CourseName = value
            End Set
        End Property
        Property StartDateFormated
            Get
                Return _StartDateFormated
            End Get
            Set(value)
                _StartDateFormated = value
            End Set
        End Property
#End Region
    End Class

    Public Class Batchs
        Public BatchList As New List(Of BatchItem)
        Public Function Contains(ByVal Batchname As String, ByVal CourseID As String)
            For Each k As BatchItem In BatchList
                If k.CourseID = CourseID And k.BatchName = Batchname Then
                    Return True
                    Exit Function
                End If
            Next
            Return False
        End Function
        Public Function Contains(ByVal Batchname As String, ByVal CourseID As String, ByVal BatchID As String)
            For Each k As BatchItem In BatchList
                If k.CourseID = CourseID And k.BatchName = Batchname Then
                    If k.BatchID = BatchID Then
                    Else
                        Return True
                        Exit Function
                    End If
                End If
            Next
            Return False
        End Function
    End Class
End Namespace

Thank you for your efforts. I am new to linq, so I may not be that good at it, your assistant and making me understand the mistake is heartily welcomed.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T13:55:00+00:00Added an answer on May 23, 2026 at 1:55 pm

    Exception does say exacly whats ur problem. Linq expression does not return List and its not assignable to List. Try surounding your whole expression in brackets and use ToList()

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have been asking myself this question for a long time now. Thought of
This is my first post, have been a lurker for a long time, so
I have been trying to make this work for a long time now. In
I have been looking at this for a long time and finally decided to
I have been trying for a long time to get SQL Server Express on
I have been in love with zsh for a long time, and more recently
I have been using attachment_fu on a project for a long time and all
I have been thinking of starting a site of my own for long time.
I'm a long-time C++ programmer developing on Windows, and have been using Visual Studio
I've been doing c# for a long time, and have never come across an

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.