Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Filtering/Searching in a MSFlexGrid control in VB6

662 views
Skip to first unread message

Michael

unread,
Oct 22, 2008, 9:28:03 AM10/22/08
to
I have a requirement of displaying a table of directory information in VB 6.
I've done this using a MSFlexGrid control. I use an array to initially
populate the control. I populate it one row at a time using the AddItem
method. The columns are tab-delimited as the rows are added. Column sorting
of the directory is done using sort method.

Filtering(searching) data is done by manually going through each and every
entry and decide if that particular row is to be displayed or not. To
display, I would just give it a normal cell height, if I need to hide it, I
just set the cell height to 0. I've decided to not use substr to filter the
data as substr is very slow, so the algorithm to filter is to compare the
entry with a search key character by character.

As the user enters the characters of the filter(search) key, the program
goes through all visible entries checking if the newly entered character is
the same as the character in the entry at the same position.

Deleting characters from the search key involves searching the hidden
entries and checking if the entry starts with the search key. This is done
by retrieving the left portion of the entry that has the same length as the
remaining search key and doing a match. A match would unhide the entry.

With this algorithm, I could reasonably search 8000 entries but as the
number of entries increases the search time exponentially increases to the
number of entries. Is there a way of improving the algorithm so that the
search becomes faster? Should I be using other controls? Are there any
libraries that I can use to improve the efficiency of the algorithm? I need
the algorithm to be able to reasonably search 40,000 to 50,000 entries. Many
thanks in advance.

JasonTheEngineer

unread,
Dec 7, 2008, 6:26:00 PM12/7/08
to
I would copy the contents of the column you're searching into an string array
redimmed to be equal in size to grid.rows, then use the algorithm against
that data. It is much faster to search againts data in an array than to scan
the text property of every cell, since accessing every cell in the control is
a slow process. At least when you do read the contents of the grid you are
making the client wait for the one load cycle. Also you may want to
investigate the efficiencies of different kinds of sorts, such as "bubble"
sorts, etc. If you populate the grid, apply the "sort" to the flex grid then
populate your string array then it will already contain presorted data, which
can make your search much faster.

I love doing this from a SQL query, it is very fast and shows only the items
that are like what the user is typing. Putting the data into a simple Jet
database might be worth the added effort if the program is expected to
perform well on a large set of data. All of the components of the database
can be self contained in your program and operate on a single MDB.

0 new messages