CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 8 of 8

Thread: Search Tool

  1. #1
    Join Date
    Feb 2009
    Posts
    192

    Search Tool

    Hallo,

    This search button works fine, however, in the tooltip it shows "Record Found" as highlighted in the code below. What I want to do is to say how many records have been found. Lets say 2 records found it says "2 Records Found". I understand a count function must be included please could anyone update the code for me to accomodate that functionality.

    Thank you very much indeed. Please find the code below;

    Code:
    Private Sub btnPerformSearch_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnPerformSearch.Click
            ' Declare local variables...
            Dim intPosition As Integer
            ' Determine the appropriate item selected and set the
            ' Sort property of the DataView object...
            Select Case cboField.SelectedIndex
                Case 0 'PRACTICE
                    objDataView.Sort = "PRACTICE"
                Case 1 'HEALTH AUTHORITY
                    objDataView.Sort = "HA_NAME"
                Case 2 'REGION
                    objDataView.Sort = "REGION"
                Case 3 'TOWN
                    objDataView.Sort = "TOWN"
                Case 4 'POSTCODE
                    objDataView.Sort = "POSTCODE"
                Case 5 'CLINCOMP
                    objDataView.Sort = "CLINCOMP"
                Case 6 'GPRDSTATUS
                    objDataView.Sort = "GPRDSTATUS"
    
            End Select
            ' If the search field is not price then...
            If cboField.SelectedIndex < 7 Then
                ' Find the practice details
                intPosition = objDataView.Find(txtSearchCriteria.Text)
    
            End If
            If intPosition = -1 Then
                ' Display a message that the record was not found...
                ToolStripStatusLabel1.Text = "Record Not Found"
            Else
                ' Otherwise display a message that the record was
                ' found and reposition the CurrencyManager to that
                ' record...
                ToolStripStatusLabel1.Text = "Record Found"
                objCurrencyManager.Position = intPosition
            End If
            ' Show the current record position...
            ShowPosition()
    
    End Sub
    Last edited by HanneSThEGreaT; June 2nd, 2009 at 09:28 AM.

  2. #2
    Join Date
    Jul 2001
    Location
    Sunny South Africa
    Posts
    11,284

    Re: Search Tool

    Would something like this :
    Code:
    ToolStripStatusLabel1.Text = objDataView.Count & " Record(s) Found"
    Work &#191;

  3. #3
    Join Date
    Feb 2009
    Posts
    192

    Count Function

    Hallo,

    I have th efollowing search code which works fine. However, I have an additional task to do, which is create a count funtion for the Record found or Record not found. Presently what it does is it searchs and if a record is found it displays at the tooltip "Record Found" if not it says "Record Not found". However, sometimes you have 2 or more records. Therefore, the tooltip should say the exact amount of records found.. For example, 3 Records Found or even 5 Records Found.

    Also if only one record is found it says "Record Found" but if more it should display " 2 Records Found".

    Please could anyone help me with the count syntax to be added to the code.. Thanks


    Code:
        Private Sub btnPerformSearch_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnPerformSearch.Click
            ' Declare local variables...
            Dim intPosition As Integer
            ' Determine the appropriate item selected and set the
            ' Sort property of the DataView object...
            Select Case cboField.SelectedIndex
                Case 0 'PRACTICE
                    objDataView.Sort = "PRACTICE"
                Case 1 'HEALTH AUTHORITY
                    objDataView.Sort = "HA_NAME"
                Case 2 'REGION
                    objDataView.Sort = "REGION"
                Case 3 'TOWN
                    objDataView.Sort = "TOWN"
                Case 4 'POSTCODE
                    objDataView.Sort = "POSTCODE"
                Case 5 'CLINCOMP
                    objDataView.Sort = "CLINCOMP"
                Case 6 'GPRDSTATUS
                    objDataView.Sort = "GPRDSTATUS"
    
            End Select
            ' If the search field is not price then...
            If cboField.SelectedIndex < 7 Then
                ' Find the practice details
                intPosition = objDataView.Find(txtSearchCriteria.Text)
    
            End If
            If intPosition = -1 Then
                ' Display a message that the record was not found...
    
                ToolStripStatusLabel1.ForeColor = Color.Red
                ToolStripStatusLabel1.Font = New Font(Font, FontStyle.Bold)
                ToolStripStatusLabel1.Text = "Record Not Found"
            Else
                ' Otherwise display a message that the record was
                ' found and reposition the CurrencyManager to that
                ' record...
                ToolStripStatusLabel1.ForeColor = Color.Red
                ToolStripStatusLabel1.Font = New Font(Font, FontStyle.Bold)
                ToolStripStatusLabel1.Text = "Record Found"
                objCurrencyManager.Position = intPosition
            End If
            ' Show the current record position...
            ShowPosition()
    
            Me.QryContactsperpracTableAdapter1.FillBy(Me.QryContacts1.QryContactsperprac, TxtPracName.Text, TxtPostcode.Text, TxtSite.Text, TxtAddress1.Text)
    End Sub
    Last edited by HanneSThEGreaT; July 14th, 2009 at 06:35 AM. Reason: Code Tags!

  4. #4
    Join Date
    Jul 2001
    Location
    Sunny South Africa
    Posts
    11,284

    Re: Count Function

    What's was wrong with this answer &#191; :

    http://www.codeguru.com/forum/showthread.php?t=478239

    Couldn't you manage to get it to work &#191;

  5. #5
    Join Date
    Feb 2009
    Posts
    192

    Re: Search Tool

    This code did not work...

    It displayed the number of all records on the tooltip

    as

    9134 Record(s) Found

    This was shown even if ONLY 2 records were present...

    any help!!!

    Thanks for the suggestion

  6. #6
    Join Date
    Feb 2009
    Posts
    192

    Re: Count Function

    This code did not work...

    It displayed the number of all records on the tooltip

    as

    9134 Record(s) Found

    This was shown even if ONLY 2 records were present...

    any help!!!

    Thanks for the suggestion

  7. #7
    Join Date
    Jul 2001
    Location
    Sunny South Africa
    Posts
    11,284

    Re: Count Function

    Hello again. I need glasses! :blash: I don't know how I could've missed this one

    You've already set it up properly actually. You already had a variable ( intPosition ) pointing to the Find results...

    Change the appropriate section to look like :
    Code:
    Else
                ' Otherwise display a message that the record was
                ' found and reposition the CurrencyManager to that
                ' record...
                ToolStripStatusLabel1.ForeColor = Color.Red
                ToolStripStatusLabel1.Font = New Font(Font, FontStyle.Bold)
                ToolStripStatusLabel1.Text = intPosition " Record(s) Found"
                objCurrencyManager.Position = intPosition
    I apologise for my blindness, it happens sometimes, but I sincerely hope it helps now.

  8. #8
    Join Date
    Feb 2009
    Posts
    192

    Re: Search Tool

    The problem is it doesn't show the number of records obtained..

    I want it to tell the user if the number of records are 2, 10, 1000 etc

    Therefore it should look like, for example - 2 Record(s) Found or 1000 Record(s) Found

    any ideas

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured