Click here to Skip to main content
12,548,514 members (46,733 online)
Click here to Skip to main content
Add your own
alternative version


12 bookmarked

Generic Record Selector With Filter

, 10 Nov 2009 CPOL
Rate this:
Please Sign up or sign in to vote.
A Generic Record Selector Windows Form with Data Filter


I've never been a big fan of the combobox as a method for selecting records, so I came up with the Record Selector. By passing a set of parameters (Dataset, column headings, etc.) to the Record Selector class library, you get a new Windows Form displaying all of the data passed into it. Multiple record selections are available, and the filter textbox filters every item as you type.

Using the Code

I have included a demo application, but basically, you need to add a reference to class library SZ-CL-0003 (I know this is not the best or most descriptive naming convention, but it's what I always use!), and declare a string array variable to assign the selected records(s) to.

The following parameters are used by the Record Selector.


A standard Although the current version only allows two columns of data to be displayed on screen, any extra columns found will be added to the tooltiptext for the record. The tooltiptext is included in the filter.


A string variable containing the title for the selection screen.


A string array containing the two columns to display on screen (I may increase this at a later date).

strfixed (Opt (Default: Nothing))

A string array of fixed items that will appear in the list for selection, but will always appear at the top of the list and will not be affected by the filter.

Each fixed item consists of a 3-bound array:

  • (0) = 1st Fixed Item 1st Column Text
  • (1) = 1st Fixed Item 2nd Column Text
  • (2) = 1st Fixed Item ToolTipText
  • (3) = 2nd Fixed Item 1st Column Text
  • (4) = 2nd Fixed Item 2nd Column Text
  • (5) = 2nd Fixed Item ToolTipText

blnmultiple (Opt (Default: True))

A boolean value to determine if multiple selections will be available. If more than one item in the list is selected, a select button will appear on the toolstrip, if only one record is required, then simply double-clicking the item will select it.

Sample Code

The following code allows the user to select a single user from a user dataset, or add a new user by selecting the <NEW> fixed line item and should be placed on a button click event.

In this example, a reference has already been added to SZ-CL-0003 and the dataset has already been created and filled.

Dim selector As New SZ_CL_0003.Selector

Private Sub btnSelectSingleAddNew_Click(ByVal sender As System.Object, _
	ByVal e As System.EventArgs) Handles btnSelectSingleAddNew.Click

   Dim strtitle As String = "Select Users"
   Dim strcolumns(2) As String
   Dim strfixed(3) As String

   strcolumns(0) = "User Code"
   strcolumns(1) = "Name"

   strfixed(0) = "<NEW>" 
   strfixed(1) = "Add New User"
   strfixed(2) = "Add a new user record to the database"

   Dim struser() As String = selector.Select_Records_
				(dataset, strtitle, strcolumns, strfixed, False)

   If struser IsNot Nothing Then

      For intloop As Integer = 0 To (UBound(struser) - 1)

         If struser(intloop) = "<NEW>" Then
            MessageBox.Show(struser(intloop), "User Selected", _
			MessageBoxButtons.OK, MessageBoxIcon.Information)
         End If


   End If

End Sub     


  • 16th April 2009 - 13:25 - Added code to allow selection using the <RTN> key, or exit without selection using the <ESC> key


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author
Software Developer (Senior) Hitachi Automotive Systems Europe Limited
United Kingdom United Kingdom
No Biography provided

You may also be interested in...

Comments and Discussions

NewsNew Version Available Pin 3:05 3:05 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Terms of Use | Mobile
Web02 | 2.8.161021.1 | Last Updated 10 Nov 2009
Article Copyright 2009 by
Everything else Copyright © CodeProject, 1999-2016
Layout: fixed | fluid