Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. Visual Basic
  4. A faster way to find an item in a bindingsource and return its index

A faster way to find an item in a bindingsource and return its index

Scheduled Pinned Locked Moved Visual Basic
databasesql-serversysadminquestion
4 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • D Offline
    D Offline
    desanti
    wrote on last edited by
    #1

    Hello ! I'm using entity framework 6 with sql server 2008r2. I have a bindingsource :

    Mybindingsource.datasource=(From t in context.myobjects order by t.name select t).ToList

    Now , I want to search inside the bindingsource , and get the found item's index. I'm using this code :

    Function findindex(startposition as integer) As integer
    Dim p as Myobject
    Dim i as integer
    For i=startposition to Mybindingsource.count-1
    p=MyBindingsource.item(i)
    if p.value=3 then return i
    Next
    return 0
    End Function

    This code is working , but when the bindingsource contains too many itmes , is very slow. Is there any faster way ? Thank you !

    L 1 Reply Last reply
    0
    • D desanti

      Hello ! I'm using entity framework 6 with sql server 2008r2. I have a bindingsource :

      Mybindingsource.datasource=(From t in context.myobjects order by t.name select t).ToList

      Now , I want to search inside the bindingsource , and get the found item's index. I'm using this code :

      Function findindex(startposition as integer) As integer
      Dim p as Myobject
      Dim i as integer
      For i=startposition to Mybindingsource.count-1
      p=MyBindingsource.item(i)
      if p.value=3 then return i
      Next
      return 0
      End Function

      This code is working , but when the bindingsource contains too many itmes , is very slow. Is there any faster way ? Thank you !

      L Offline
      L Offline
      Lost User
      wrote on last edited by
      #2

      desanti wrote:

      This code is working , but when the bindingsource contains too many itmes , is very slow. Is there any faster way ?

      Yes, select by primary key instead of an index.

      Bastard Programmer from Hell :suss: If you can't read my code, try converting it here[^] "If you just follow the bacon Eddy, wherever it leads you, then you won't have to think about politics." -- Some Bell.

      D 1 Reply Last reply
      0
      • L Lost User

        desanti wrote:

        This code is working , but when the bindingsource contains too many itmes , is very slow. Is there any faster way ?

        Yes, select by primary key instead of an index.

        Bastard Programmer from Hell :suss: If you can't read my code, try converting it here[^] "If you just follow the bacon Eddy, wherever it leads you, then you won't have to think about politics." -- Some Bell.

        D Offline
        D Offline
        desanti
        wrote on last edited by
        #3

        Sorry , I need to get the index of found item in bindingsource.

        L 1 Reply Last reply
        0
        • D desanti

          Sorry , I need to get the index of found item in bindingsource.

          L Offline
          L Offline
          Lost User
          wrote on last edited by
          #4

          Than you will have to deal with a slow bindingsource.

          Bastard Programmer from Hell :suss: If you can't read my code, try converting it here[^] "If you just follow the bacon Eddy, wherever it leads you, then you won't have to think about politics." -- Some Bell.

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups