Click here to Skip to main content
Click here to Skip to main content

Generic Record Selector With Filter 2

, 10 Nov 2009 CPOL
Rate this:
Please Sign up or sign in to vote.
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, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Share

About the Author

system-zone.co.uk
Software Developer (Senior) Hitachi Automotive Systems Europe Limited
United Kingdom United Kingdom
No Biography provided

Comments and Discussions

 
GeneralMy vote of 2 PinmvpSacha Barber22-Nov-09 2:25 
not generic enough
QuestionWhere is the source? PinmemberGlimmerMan20-Nov-09 6:18 
Generalhi Pinmemberkonikula17-Nov-09 5:39 
GeneralRe: hi Pinmemberkonikula14-Dec-09 14:08 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Terms of Use | Mobile
Web02 | 2.8.141223.1 | Last Updated 10 Nov 2009
Article Copyright 2009 by system-zone.co.uk
Everything else Copyright © CodeProject, 1999-2014
Layout: fixed | fluid