How to search for a certain record in a MSHFlexGrid?
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4

Thread: How to search for a certain record in a MSHFlexGrid?

Hybrid View

  1. #1
    Join Date
    Jun 2012
    Posts
    13

    How to search for a certain record in a MSHFlexGrid?

    I have a MSHFlexGrid that gets all records via a recordset from a database.
    I want to add a search function so that it would search for the data entered by the user on to the search textbox. But it should search for the data only in a certain column in the MSHFlexGrid.
    Can anyone please give me the code for this?

    And I'm very sorry if the question is not clear. If it is not, please inform me. I will do my best to make it more understandable.

  2. #2
    Join Date
    Jan 2006
    Location
    Chicago, IL
    Posts
    14,999

    Re: How to search for a certain record in a MSHFlexGrid?

    You shouldn't be loading ALL RECORDS of anything into the grid. The user needs to see between 1 and 25 records (one screen).

    You would have to QUERY each record as a separate QUERY, or else FILTER based on the records.

    You CAN load the data into a recordset and procress it from there, though. Just don't BIND it to the grid.

    I have an article that uses a grid. You can find it here
    David

    CodeGuru Article: Bound Controls are Evil-VB6
    2013 Samples: MS CODE Samples

    CodeGuru Reviewer
    2006 Dell CSP
    2006, 2007 & 2008 MVP Visual Basic
    If your question has been answered satisfactorily, and it has been helpful, then, please, Rate this Post!

  3. #3
    Join Date
    Aug 2003
    Location
    Sydney, Australia
    Posts
    1,854

    Re: How to search for a certain record in a MSHFlexGrid?

    Its true you shouldn't load 300,000 records into a grid as this will be a badly designed application - however a few hundred, even a few thousand rows does not upset your program speed so lond as you have a good sized memory - 2-4GB minimum

    To answer your question about searching through a grid, you could do the following
    Lets say your Search Column is Customer Code from a Table Called Customers

    You could simply say "Select * from Customers Where Customer_Code = '" & Text1.text & "'"
    Then execute the select statement to get the record you wanted
    This would negate the need for filling a grid and would happily work on a table with 1000, 10000, or 100000 records without problem


    Lets now assume you have run a query something like
    "Select Record_Type, Customer_Code, Customer_Name from Customers "
    - and have filled the grid below

    Grid.FormatString = " |<Record Type |<Customer Code |<Customer Name "

    To find a Customer Code (value in Text1.text ) in Column Number 2 (1st column = Column 0) you would simply say

    Dim R as long
    Dim C as long
    For R = 1 to Grid.Rows -1
    Grid.Row = R
    Grid.Col = 2
    If Grid.text = Text1.text then
    MSGBOX " Record Found"
    Goto .......................
    EndIf
    Next R

    MSGBOX " Record NOT Found"

    Goto ..........................


    If you are dealing with a large amount of data in a grid then, to speed things up, do as follows

    Dim R as long
    Dim C as long
    Grid.Visible = False
    Grid.Redraw = False

    For R = 1 to Grid.Rows -1
    Grid.Row = R
    Grid.Col = 2
    If Grid.text = Text1.text then
    Grid.Visible = True
    Grid.Redraw = True
    MSGBOX " Record Found"

    Goto .......................
    EndIf
    Next R

    Grid.Visible = True
    Grid.Redraw = True
    MSGBOX " Record NOT Found"

    Goto ..........................



    PS -WHERE HAS THE CODE BLOCKING ICON DISAPPEARED TO ?
    (Is this another W7 ? - Cant seem to find anything, anymore)
    Last edited by George1111; September 9th, 2012 at 09:46 AM.

  4. #4
    Join Date
    Jan 2006
    Location
    Chicago, IL
    Posts
    14,999

    Re: How to search for a certain record in a MSHFlexGrid?

    Its true you shouldn't load 300,000 records into a grid as this will be a badly designed application - however a few hundred, even a few thousand rows does not upset your program speed so lond as you have a good sized memory - 2-4GB minimum
    Guess you've never had a SQL SERVER w/5000 users each accessing the same 1,000 records.

    Why read 100 records unless you plan to process them ALL?

    Also, code tags are in with quote tags (in ADVANCED EDITOR). You know you can also just TYPE the quote tags yourself?
    David

    CodeGuru Article: Bound Controls are Evil-VB6
    2013 Samples: MS CODE Samples

    CodeGuru Reviewer
    2006 Dell CSP
    2006, 2007 & 2008 MVP Visual Basic
    If your question has been answered satisfactorily, and it has been helpful, then, please, Rate this Post!

Tags for this Thread

Posting Permissions

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


Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center