Monday, January 17, 2011

Populating combbox using a List with two columns

        uList = SybizDB.GetUserList
        cbUser.DataSource = uList
        cbUser.DisplayMember = "Name"
        cbUser.ValueMember = "UserNumber"

easy as that.
displaying the name field while selecting the actual value of usernumber field.

Friday, January 14, 2011

SQL Selection Queries

To compare two table values and select the ones that aren't common, say common field is ProductID:


        select ProductID from Table1 where ProductID not in (select ProductID from Table2)

Tuesday, January 11, 2011

Dynamically create tab control in VB.NET

Creating a tab control with textbox/label/buttons:


    Private tabSupplierArray As System.Windows.Forms.TabControl
    Private lableArray(3) As Label
    Private txtSuppArray(3) As TextBox


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

        'Create and set position of tab control
        Dim tabControl As New TabControl()
        tabControl.Location = New System.Drawing.Point(0, 10)
        tabControl.Size() = New Size(900, 200)

        Dim fnt As New Font("Courier New", 9.75)

        'Loop 8 times to create 8 tab pages---------------------------------------
        For c As Integer = 1 To 8
            Dim tabPage As New TabPage()
            Dim btnSup As New Button()

            If c = 1 Then
                tabPage.Text = "Preferred Supplier"
            Else
                tabPage.Text = c.ToString()
            End If

            Dim txtCode As New TextBox
            'Creating labels and textbox horizontally twice----------------------
            For i As Integer = 0 To 1
                lableArray(i) = New System.Windows.Forms.Label
                With lableArray(i)
                    .Size() = New Size(40, 22)
                    .Font = fnt
                    .Location = New System.Drawing.Point(30 + (i * 350), 30)
                    .TextAlign = HorizontalAlignment.Right
                End With
                txtSuppArray(i) = New System.Windows.Forms.TextBox
                With txtSuppArray(i)
                    If i = 0 Then
                        .Size() = New Size(150, 22)
                    Else
                        .Size() = New Size(367, 22)
                    End If
                    .ReadOnly = True
                    .Location = New System.Drawing.Point(130 + (i * 350), 30)
                    .TextAlign = HorizontalAlignment.Left
                End With
            Next
            'Creating labels and textbox horizontally twice----------------------
            For i As Integer = 2 To 3
                lableArray(i) = New System.Windows.Forms.Label
                With lableArray(i)
                    .Size() = New Size(100, 22)
                    .Font = fnt
                    .Location = New System.Drawing.Point(30 + ((i - 2) * 350), 70)
                    .TextAlign = HorizontalAlignment.Right
                End With
                txtSuppArray(i) = New System.Windows.Forms.TextBox
                With txtSuppArray(i)
                    If i = 2 Then
                        .Size() = New Size(200, 22)
                    Else
                        .Size() = New Size(367, 22)
                    End If
                    .MaxLength = 30
                    .Location = New System.Drawing.Point(130 + ((i - 2) * 350), 70)
                    .TextAlign = HorizontalAlignment.Left
                End With
            Next
            lableArray(0).Text = "Code"
            lableArray(1).Text = "Name"
            lableArray(2).Text = "Part Number"
            lableArray(3).Text = "Notes"

            'Create button-----------------------------------
            With btnSup
                .Size() = New Size(45, 22)
                .Location = New System.Drawing.Point(285, 30)
                .Font = fnt
                .Text = "Btn"
            End With

            'Add controls onto tab control---------
            tabPage.Controls.Add(btnSup)
            tabPage.Controls.AddRange(lableArray)
            tabPage.Controls.AddRange(txtSuppArray)
            tabControl.Controls.Add(tabPage)
        Next

        Me.Controls.Add(tabControl)

    End Sub