Quantcast
Channel: VBForums - Visual Basic .NET
Viewing all articles
Browse latest Browse all 27554

VS 2010 Adding DataBindings

$
0
0
I'm creating a login where my data is stored in an XML file and I'm having an issue adding databindings to my two textboxes and a checkbox. What I'm doing is:

A) Loading a DataSet from an XML file:
Code:

    Private Sub CreateDatatable(ByVal path As String)
        ds = New DataSet
        ds.ReadXml(path)

    End Sub

B) Checking for a username/password match:
Code:

            'column 0 is the ID
            'column 1 is the User
            'column 2 is the Pass
            'column 3 checks for the admin rights
            Dim dt As DataTable = ds.Tables(0)

            Dim IsMatch As Boolean = False
            Dim IsAdmin As Boolean = False
            For i As Integer = 0 To dt.Rows.Count - 1
                If dt.Rows(i)(1).ToString = user AndAlso dt.Rows(i)(2).ToString = pass Then
                    IsMatch = True

                    If dt.Rows(i)(3).ToString = "true" Then
                        IsAdmin = True
                    End If

                    Exit For
                End If
            Next

C) Then if there is a match and the user is an admin, load up my admin form:
Code:

If IsMatch AndAlso IsAdmin Then
                'If the user is an admin
                Dim admin_form As New FormAdmin

                'admin_form.ds is a public DataSet
                admin_form.ds = ds

                admin_form.Show()

D) In my admin_form's load event I set up a bindingsource and set all the databindings:
Code:

    Private Sub FormAdmin_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
        BindingSource1.DataSource = ds.Tables(0)

        DataGridView1.DataSource = BindingSource1.DataSource
        txt_remove_user.DataBindings.Add("Text", BindingSource1, "User")
        txt_remove_pass.DataBindings.Add("Text", BindingSource1, "Pass")
        cb_remove_admin.DataBindings.Add("Checked", BindingSource1, "User")

    End Sub

The issue that I'm having is that my DataGridView shows the data no problem, however my two textboxes and checkbox don't do anything at all. Take a look at the picture:
Name:  unsafe.png
Views: 90
Size:  20.2 KB

Am I just adding the databindings wrong? I'm expecting the txt_remove_user and txt_remove_pass to read column1 and column2 of the selected row of the datagridview.
Attached Images
 

Viewing all articles
Browse latest Browse all 27554

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>