Click here to Skip to main content
65,938 articles
CodeProject is changing. Read more.
Articles
(untagged)

Generic Record Selector With Filter 2

0.00/5 (No votes)
10 Nov 2009 1  
An update to my original generic record selector.

Introduction

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.

  • dataset
  • A standard System.Data.DataSet. This can contain as many columns of data as required.

  • strtitle
  • A String variable containing the title for the selection screen.

  • strcolumns
  • A 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.

  • strstatics
  • 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 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 = False))
  • 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.

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 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
                Add_New_User
            Else
                MessageBox.Show(struser(intloop), "User Selected", _
                    MessageBoxButtons.OK, MessageBoxIcon.Information)
            End If
        Next
    End If
    
End Sub

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here