Click here to Skip to main content
15,867,330 members
Articles / Programming Languages / Visual Basic 10

Generic Record Selector With Filter 2

Rate me:
Please Sign up or sign in to vote.
2.60/5 (2 votes)
10 Nov 2009CPOL2 min read 21.5K   138   12   4
An update to my original generic record selector.

Image 1

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.

VB
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, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Software Developer (Senior) Hitachi Automotive Systems Europe Limited
United Kingdom United Kingdom
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions

 
GeneralMy vote of 2 Pin
Sacha Barber22-Nov-09 1:25
Sacha Barber22-Nov-09 1:25 
QuestionWhere is the source? Pin
karenpayne20-Nov-09 5:18
karenpayne20-Nov-09 5:18 
Generalhi Pin
konikula17-Nov-09 4:39
konikula17-Nov-09 4:39 
GeneralRe: hi Pin
konikula14-Dec-09 13:08
konikula14-Dec-09 13:08 

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.