I posted an article in April of this year which introduced version 1 of this class module which allowed the developer to pass in some basic settings with a dataset to produce a selection screen which gave the user the ability filter to the dataset and then select the required record.
Version 1 has a couple of limitations: the form is a fixed size, and the view only allows two columns. Both of these limitations are removed in version 2.
Using the Code
The use of the class is the same as in version 1, but the arguments passed into it have changed.
System.Data.DataSet. This can contain as many columns of data as required.
String variable containing the title for the selection screen.
String array containing the columns to display on screen. Each attribute of the array should contain the column header and width separated by a comma (e.g., "User Name,200"). On loading, the form will stretch to include all of the columns specified up to the width of the user's screen, at which point a horizontal scroll bar will appear.
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 attribute of the array contains one row of data to be displayed on the form, with commas used to separate the columns, (e.g., "IWALLACE,Ian Wallace")
blnmultiple (optional (default =
A boolean value to determine if multiple selections will be available. If set to
True, then multiple records can be selected by CTRL-clicking the rows. An Accept button will appear on the toolstrip once the first row has been selected.
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 SZCL00001, and the dataset has already been created and filled.
Dim selector As New SZCL00001.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(1) As String
strcolumns(0) = "User Code,150"
strcolumns(1) = "Name,250"
strcolumns(2) = "Title,250"
strfixed(0) = "<NEW>,Add A New User"
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", _