Filter on a Listbox?

Is there possible to make filters on a Listbox as an Excel Spreadsheet?

For example in a table with 20 customers, If I only want to display the records of the Customer Number 4.

Thanks

In this case, you shouldn’t treat the listbox as a storage container, rather as a display view. Hold the data in a separate data structure and apply the “filter” when you load the listbox (only adding the rows that pass the filter). Treat the listbox as a throw-away entity.

Ok Yeah,I know that Listbox is not a storage container, just a viewer. That I want to know is that exists a way to draw a triangle on the column header of the listbox and display a list of customers.

And when I press x or y customer, Then Makes a Recordset based on the customer that I choose.

Well, that’s that Im Thinking.

You can use MenuItem.Popup() to position a popup list next to a DisclosureTriangle.

Do a whole search, select all lines (Rows) with the search value, store them somewhere (in the Clipboard or in an object of yours, delete all data in the current ListBox and set these Rows back.

Ask if I am not crystal clear.

This is the way to do it. If you create an array of businessobjects, you can hold a reference to the related businessobject in a celltag in order to pass it to somewhere else if the user doubleclicks it etc.
When you benchmark you see populating the listbox is taking most of the time, 10000 records, 2 columns takes nearly 2 sec to populate the data to the listbox while it takes just 40 mSec to get 10000 records from a simple SQLite database and creating the array of objects. So the listbox is the slowest part which may hit you if you want to update it every time the user hits the keyboard in the filter-box.
I’ve seen @Kem Tekinay has a smart and fast alternative for the standard listbox. Need to play with it, since it’s an issue in nearly every database-application I make.

I Made a Recordset on the Database Table using Distinct to get the Customers name. and then For each customer or recordset record add a New Menu Item. I’ve done this using the event ConstructContextualMenu of the listbox.

But when I make right click on any area of the listbox,shows the menu.

But I want to appear different menu on each column.

Is this possible?

Thanks

[quote=207031:@Gerardo García]I Made a Recordset on the Database Table using Distinct to get the Customers name. and then For each customer or recordset record add a New Menu Item. I’ve done this using the event ConstructContextualMenu of the listbox.

But when I make right click on any area of the listbox,shows the menu.

But I want to appear different menu on each column.

Is this possible?

Thanks

[/quote]

Yes it is… How do you want it to work?

ConstructContexrualMenu gives you the coordinates of the clicl. To Find out what column do:

Dim ClickedColumn as Integer = me.ColumnFromXY(X,y)

It will return -1 if you click on an empty row or in a scrollbar.

ConstructContexrualMenu won’t fire if you click in a header. If you want put up a menu for for a contexual click in a header you will need to use MouseDown and create the contextual menu yourself (which is not hard)

  • Karen