Click here to Skip to main content
13,295,243 members (71,372 online)
Click here to Skip to main content
Add your own
alternative version


11 bookmarked
Posted 9 Nov 2009

Generic Record Selector With Filter 2

, 10 Nov 2009
Rate this:
Please Sign up or sign in to vote.
An update to my original generic record selector.


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


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

GeneralMy vote of 2 Pin
Sacha Barber22-Nov-09 2:25
mvpSacha Barber22-Nov-09 2:25 
QuestionWhere is the source? Pin
GlimmerMan20-Nov-09 6:18
memberGlimmerMan20-Nov-09 6:18 
Generalhi Pin
konikula17-Nov-09 5:39
memberkonikula17-Nov-09 5:39 
GeneralRe: hi Pin
konikula14-Dec-09 14:08
memberkonikula14-Dec-09 14:08 
But yeah, I should post some better, shouldn't I.. when making inhume critics? Smile | :)

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.

Permalink | Advertise | Privacy | Terms of Use | Mobile
Web04 | 2.8.171207.1 | Last Updated 10 Nov 2009
Article Copyright 2009 by
Everything else Copyright © CodeProject, 1999-2017
Layout: fixed | fluid