Solved

VB.NET bindingsource.find not working

Posted on 2010-11-16
2
1,570 Views
Last Modified: 2012-05-10
This is a second part to http://www.experts-exchange.com/Programming/Languages/.NET/Visual_Basic.NET/Q_26616925.html#a34147039

I have a form that opens with a bindingsource on it and I want to set it to a particular record.  In the form, I have the following:
 
Public Sub New(ByVal idNum As Integer)

        InitializeComponent()

        Debug.WriteLine("ID passed = " & idNum)

        Dim row As Integer

        row = CustomerTBLBindingSource.Find("CustomerID", row)        

        Debug.WriteLine("Index=" & row)

        If row <> -1 Then

            CustomerTBLBindingSource.Position = row

        End If

Open in new window


I can't get the find to work for the life of me!  The table has 3 records with CustomerIDs of 1,2 and 3.  The field is set to the primary key with a value of int.  I even tried:

    row = CustomerTBLBindingSource.Find("LastName", "Bob")

Where one of the records has Bob for the LastName, but it always returns an index of -1.  I have found all kinds of examples identical to this and they seem to work for everyone else.  Any ideas what's wrong or how I can debug it?
0
Comment
Question by:roarteam
2 Comments
 
LVL 83

Accepted Solution

by:
CodeCruiser earned 500 total points
Comment Utility
"The Find method can only be used when the underlying list is an IBindingList with searching implemented."

http://msdn.microsoft.com/en-us/library/ms158165.aspx
0
 

Author Comment

by:roarteam
Comment Utility
Thanks CodeCruiser.  What I did was use the filter property instead:
 
Me.CustomerTBLBindingSource.Filter = "CustomerID = " & idNum

Open in new window

Works like a charm!
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

More often than not, we developers are confronted with a need: a need to make some kind of magic happen via code. Whether it is for a client, for the boss, or for our own personal projects, the need must be satisfied. Most of the time, the Framework…
A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…

728 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now