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.
system.data.dataset. 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.
string variable containing the title for the selection screen.
string array containing the two columns to display on screen (I may increase this at a later date).
strfixed (Opt (Default: Nothing))
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.
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", _
- 16th April 2009 - 13:25 - Added code to allow selection using the <RTN> key, or exit without selection using the <ESC> key