Results 1 to 6 of 6

Thread: Find a row in FlexGrid by typing first letters

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Apr 2005
    Posts
    105

    Find a row in FlexGrid by typing first letters

    Hi all,
    How to find a row in a flex grid by typing the first letters of that row.
    For example: I use a flex grid to list the names of all countries. Now I want findout Tunisia or Turkey by typing TU....

    I think it is possible using a ListBox or ComboBox, but in my case I want this facility using a flex grid

    With regards,
    Nasreen

  2. #2
    PowerPoster
    Join Date
    Oct 2002
    Location
    British Columbia
    Posts
    9,758

    Re: Find a row in FlexGrid by typing first letters

    Loop thru all the rows in the grid until a match is found. If the form has a textbox where the search criteria is entered put your code in the Change event.

    Code:
    Private Sub txtSearch_Change()
        Dim row As Long
        
        For row = 0 To grdCountries.Rows - 1
            If InStr(1, grdCountries.TextMatrix(row, <Column # that contains country name>), txtSearch.Text, vbTextCompare) = 1 Then
                grdCountries.row = row
                grdCountries.TopRow = row
                Exit For
            End If
        Next
    End Sub

  3. #3

    Thread Starter
    Lively Member
    Join Date
    Apr 2005
    Posts
    105

    Re: Find a row in FlexGrid by typing first letters

    Hi brucevde
    Thanks for your reply
    But your idea doesn't meet my requirement
    In my project I use a FlexGrid listing all countires to be selected by the user. This flexgrid is place in a separate Form and form is showed as vbModal. There is no any textbox in it (Please see the attached screenshot)
    I need when a customer type the first letter of a country, the first row starting with the typed letter should be selected.
    For example, if the user type letter I, the focus go to India, if he again type the same letter the focus go to the next country Indonesia and for again B]I[/B] the focus goes to Iran.
    Now if the user type two letters IR simultaniously, the focus go to Iran. If the user type CH, the focus go to China.

    How can perform this with a FlexGrid ? or is there any other special grid we can use in VB to do like this ?

    Any help is highly appreciated

    Regards,
    nasreen
    Attached Images Attached Images  

  4. #4
    PowerPoster
    Join Date
    Oct 2002
    Location
    British Columbia
    Posts
    9,758

    Re: Find a row in FlexGrid by typing first letters

    The basic idea of using a Loop still applies.

    Since there is no textbox where the user enters their search criteria, you will have to use the KeyPress event.

    For example, if the user type letter I, the focus go to India, if he again type the same letter the focus go to the next country Indonesia
    To implement the above, simply start the loop from the current row + 1 instead of always starting at Row 0.

  5. #5

    Thread Starter
    Lively Member
    Join Date
    Apr 2005
    Posts
    105

    Re: Find a row in FlexGrid by typing first letters

    Hi brucevde

    Your idea is almost OK for me. But this is not fully functional for my requirment.
    This idea helps finding the row depending on the first letter only.

    How we can find a row depending on first two or three letters ?

    In my example, if a user type IR simultaniously the focus should go to row of IRAN. If one types BR atonce the row of BRAZIL should be selected, if one types MAU three letters speedly, the row of MAURITIUS should be selected.

    How we can code for this kind of actions ?

    With regards,
    Nasreen

  6. #6
    PowerPoster
    Join Date
    Oct 2002
    Location
    British Columbia
    Posts
    9,758

    Re: Find a row in FlexGrid by typing first letters

    Did you even try to code this yourself?

    Basic idea. Have two module level variables that store the current letters entered by the user and the grid row where searching should begin. Use a timer to clear both these variables when appropriate.

    When a key is hit add the character to the "current letters" variable and run the search loop. The loop goes from "current search row" to total grid rows. If the current key is the same as the previous key don't add it to the current letters variable but begin search from "current search row + 1".

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