Click here to Skip to main content
15,887,822 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
First: Programming with Visual Basic 2012 (WinForm). SQLExpress 2012 as my SQL server.

I am VERY green at VB and am attempting to do the following:
Input a Load Number into a Textbox. The load number will be found in one of 2 fields (PETS_LOAD_NUMBER or PRIME_LOAD_NUMBER) but not both. Once the load number is located I then want to move to the record in the dataset. I do not want a dataset loaded where only that record loads.

In essence I am wanting to replicate the functionality of MS ACCESS, where you type in the "search" box and it automatically goes to the record.

Here is what I have thus far but having one issue. The initial usage of the search box requires me to hit enter two times. Once the result is found and moved to the record, then any subsequent search requires only one tap of the enter button and all works as intended.

VB
Private Sub NavSearchBtnLoad_Click(sender As System.Object, e As System.EventArgs) Handles NavSearchBtnLoad.Click
    'General Declarations
    Dim DB_REC_CNT As Int16 = LoadInfoDataSet.Load_Info_Table.Count 'Counts Records in Database
    Dim SrchVal As String = SrchLoadInputAll.Text 'This is Load Number your searching for
    Dim IdVal As Integer 'ID of record found
    Dim SrchResult As Boolean = False 'Did search pass/fail default is fail
    Dim LoopCnt As Int16 'Loop integer

    'Perform Search
    For LoopCnt = 0 To DB_REC_CNT - 1 ' Loops thru listboxes searching for the load number
        Try
            If LoadInfoDataSet.Load_Info_Table.Item(LoopCnt).PETS_LOAD_NUMBER = SrchVal Then SrchResult = True
            If LoadInfoDataSet.Load_Info_Table.Item(LoopCnt).PRIME_LOAD_NUMBER = SrchVal Then SrchResult = True
            If SrchResult = True Then
                IdVal = LoopCnt
                LoopCnt = DB_REC_CNT - 1 ' Stops searching before end of list if found
            End If
        Catch ex As Exception
        End Try
    Next

    Try
        If SrchResult = False Then
            ' Display a message box notifying users the record cannot be found.
            If MessageBox.Show("NO RECORD FOUND. PLEASE RETRY YOUR SEARCH", "P.E.T.S. DATA MANAGEMENT SYSTEM", _
                  MessageBoxButtons.OK, MessageBoxIcon.Information) _
                = DialogResult.OK Then
            End If
            Exit Sub
        End If

    Catch ex As Exception

    End Try
    'Copy ID to Navigator and Run
    Try
        Dim ID As String = LoadInfoDataSet.Load_Info_Table.Item(IdVal).ID
        BindingNavigator1.PositionItem.Text = ID
        'Code For clicking to go to selected record
        BindingNavigatorPositionItem.Focus()
        BindingNavigator1.Focus()
        BindingNavigator1.Update()
    Catch ex As Exception
    End Try

End Sub
Posted
Updated 7-Jan-15 16:34pm
v3
Comments
CHill60 7-Jan-15 7:27am    
Can you clarify - are you trying to move to a record in the dataset (which is what yours words imply) or move to a position in one or more ListBox (which is what your code implies)
K3JAE 7-Jan-15 11:24am    
I am trying to move to a record in a dataset. I was trying to get the ID number of the record once it is found by searching for the Load Number - pass the ID number to the BindingNavigatorPositionItem which then takes me to that row in the dataset.

I cleaned my code a bot and have gotten this far with it. Only issue right now is that I must hit my "SEARCH" button 2 times for the code to work. ONCE the code does what it is supposed to do if I search another load number, hitting SEARCH button once, it then goes to the record. What is causing me to hit SEARCH twice on the initial usage of the search box but then only once afterwards?

I'm up for any new or different ideas.

instead of using

C#
BindingNavigator1.PositionItem.Text


Try
C#
BindingNavigator1.BindingSource.Position
 
Share this answer
 
Had to add a "-1" to the end of it as the result took me one record too far. IE: BindingNavigator1.BindingSource.Position = ID - 1

Other than that, all is well - Thank you.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month


CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900