Click here to Skip to main content
15,879,535 members
Articles / Programming Languages / Visual Basic

Generic Record Selector With Filter

Rate me:
Please Sign up or sign in to vote.
3.67/5 (2 votes)
10 Nov 2009CPOL2 min read 22.7K   308   13  
A Generic Record Selector Windows Form with Data Filter
Public Class frmDemo

    Dim selector As New SZ_CL_0003.Selector
    Dim dataset As New DataSet

    Private Sub Create_Dataset()

        Dim table As New System.Data.DataTable
        Dim strrow(2) As String

        table.Columns.Add()
        table.Columns.Add()
        table.Columns.Add()

        table.Columns(0).ColumnName = "DEVELOPER"
        table.Columns(1).ColumnName = "NAME"
        table.Columns(2).ColumnName = "TITLE"

        strrow(0) = "IWALLACE"
        strrow(1) = "Ian Wallace"
        strrow(2) = "Developer"
        table.Rows.Add(strrow)

        strrow(0) = "JBLOGGS"
        strrow(1) = "Joe Bloggs"
        strrow(2) = "Developer"
        table.Rows.Add(strrow)

        strrow(0) = "ENIGMA"
        strrow(1) = "Edward Nigma"
        strrow(2) = "Developer"
        table.Rows.Add(strrow)

        DataSet.Tables.Add(table)

    End Sub

    Private Sub frmDemo_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

        Create_Dataset()

    End Sub

    Private Sub btnSelectSingle_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSelectSingle.Click

        Dim strtitle As String = "Select Developers"
        Dim strcolumns(2) As String

        strcolumns(0) = "Developer Code"
        strcolumns(1) = "Name"

        Dim struser() As String = selector.Select_Records(dataset, strtitle, strcolumns, , False)

        If struser IsNot Nothing Then

            MessageBox.Show(struser(0), "Developer Selected", MessageBoxButtons.OK, MessageBoxIcon.Information)

        End If

    End Sub

    Private Sub btnSelectMultiple_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSelectMultiple.Click

        Dim strtitle As String = "Select Developers"
        Dim strcolumns(2) As String

        strcolumns(0) = "Developer Code"
        strcolumns(1) = "Name"

        Dim struser() As String = selector.Select_Records(dataset, strtitle, strcolumns, , True)

        If struser IsNot Nothing Then

            For intloop As Integer = 0 To (UBound(struser) - 1)

                MessageBox.Show(struser(intloop), "Developer Selected", MessageBoxButtons.OK, MessageBoxIcon.Information)

            Next

        End If

    End Sub

    Private Sub btnSelectSingleAddNew_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSelectSingleAddNew.Click

        Dim strtitle As String = "Select Developers"
        Dim strcolumns(2) As String
        Dim strfixed(3) As String

        strcolumns(0) = "Developer Code"
        strcolumns(1) = "Name"

        strfixed(0) = "<NEW>"                                       '   Column 1
        strfixed(1) = "Add New Developer"                           '   Column 2
        strfixed(2) = "Add a new developer record to the database"  '   Tooltip

        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)

                MessageBox.Show(struser(intloop), "Developer Selected", MessageBoxButtons.OK, MessageBoxIcon.Information)

            Next

        End If

    End Sub

End Class

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

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