Results 1 to 9 of 9

Thread: [Resolved] [2008] Databindings Problem

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Apr 2008
    Posts
    101

    Exclamation [Resolved] [2008] Databindings Problem

    I know $10 isn't much, but I'm a student and it's my college project we're talking about. It's a problem that's preventing me from continuing work on it. Even my computing teacher is stumped, so he's given me the go-ahead to do this. Typically, as a student, there's barely a dime in my bank account so I can't offer much more.

    This is the form I'm having problems with. As you can see I've created a tab interface which is working. There are five text boxes on it which are binded to the Staff table in the database. When the tab is changed, the binding is changed to a new field. However, unfortunately, when a new record is selected, the data bindings do not update, and instead, the first record is always being used. We suspect the problem may be coming from the fact that there is code to unbind from the text box and rebind it again. This is the code I'm talking about...

    Code:
        Private Sub TabCheck()
            If TabState = 1 Then
                pnlTabs.BackgroundImage = My.Resources.tabs1
                txtBox1.Visible = True
                txtBox2.Visible = True
                txtBox3.Visible = True
                txtBox4.Visible = False
                txtBox5.Visible = False
                lblBox1.Text = "Colleague ID"
                lblBox2.Text = "Colleague Role"
                lblBox3.Text = "Colleague Access Level"
                lblBox4.Text = ""
                lblBox5.Text = ""
                Me.txtBox1.DataBindings.Remove(Me.txtBox1.DataBindings("Text"))
                Me.txtBox2.DataBindings.Remove(Me.txtBox2.DataBindings("Text"))
                Me.txtBox3.DataBindings.Remove(Me.txtBox3.DataBindings("Text"))
                Me.txtBox1.DataBindings.Add(New Binding("Text", UberData.Staff, "ColleagueID"))
                Me.txtBox2.DataBindings.Add(New Binding("Text", UberData.Staff, "ColleagueRole"))
                Me.txtBox3.DataBindings.Add(New Binding("Text", UberData.Staff, "ColleagueAccessLevel"))
                StaffBindingSource.Position += 1
            Else
                If TabState = 2 Then
                    pnlTabs.BackgroundImage = My.Resources.tabs2
                    txtBox1.Visible = True
                    txtBox2.Visible = True
                    txtBox3.Visible = True
                    txtBox4.Visible = True
                    txtBox5.Visible = True
                    lblBox1.Text = "Colleague Surname"
                    lblBox2.Text = "Colleague First Name"
                    lblBox3.Text = "Date of Birth"
                    lblBox4.Text = "Home Phone Number"
                    lblBox5.Text = "Mobile Number"
                    Me.txtBox1.DataBindings.Remove(Me.txtBox1.DataBindings("Text"))
                    Me.txtBox2.DataBindings.Remove(Me.txtBox2.DataBindings("Text"))
                    Me.txtBox3.DataBindings.Remove(Me.txtBox3.DataBindings("Text"))
                    Me.txtBox4.DataBindings.Remove(Me.txtBox4.DataBindings("Text"))
                    Me.txtBox5.DataBindings.Remove(Me.txtBox5.DataBindings("Text"))
                    Me.txtBox1.DataBindings.Add(New Binding("Text", UberData.Staff, "ColleagueSurname"))
                    Me.txtBox2.DataBindings.Add(New Binding("Text", UberData.Staff, "ColleagueFirstNames"))
                    Me.txtBox3.DataBindings.Add(New Binding("Text", UberData.Staff, "ColleagueDOB"))
                    Me.txtBox4.DataBindings.Add(New Binding("Text", UberData.Staff, "ColleaguePhoneNumber"))
                    Me.txtBox5.DataBindings.Add(New Binding("Text", UberData.Staff, "ColleagueMobileNumber"))
                Else
                    If TabState = 3 Then
                        pnlTabs.BackgroundImage = My.Resources.tabs3
                        txtBox1.Visible = True
                        txtBox2.Visible = True
                        txtBox3.Visible = True
                        txtBox4.Visible = False
                        txtBox5.Visible = False
                        lblBox1.Text = "Colleague Post Code"
                        lblBox2.Text = "Colleague City"
                        lblBox3.Text = "Colleague Street"
                        lblBox4.Text = ""
                        lblBox5.Text = ""
                        Me.txtBox1.DataBindings.Remove(Me.txtBox1.DataBindings("Text"))
                        Me.txtBox2.DataBindings.Remove(Me.txtBox2.DataBindings("Text"))
                        Me.txtBox3.DataBindings.Remove(Me.txtBox3.DataBindings("Text"))
                        Me.txtBox1.DataBindings.Add(New Binding("Text", UberData.Staff, "ColleaguePostCode"))
                        Me.txtBox2.DataBindings.Add(New Binding("Text", UberData.Staff, "ColleagueCity"))
                        Me.txtBox3.DataBindings.Add(New Binding("Text", UberData.Staff, "ColleagueStreet"))
                    Else
                        If TabState = 4 Then
                            pnlTabs.BackgroundImage = My.Resources.tabs4
                            txtBox1.Visible = True
                            txtBox2.Visible = True
                            txtBox3.Visible = True
                            txtBox4.Visible = True
                            txtBox5.Visible = True
                            lblBox1.Text = "Hours Per Week"
                            lblBox2.Text = "Hourly Pay Rate"
                            lblBox3.Text = "Date Joined Company"
                            lblBox4.Text = "Currently on Holiday?"
                            lblBox5.Text = "Next Due Holiday Date"
                            Me.txtBox1.DataBindings.Remove(Me.txtBox1.DataBindings("Text"))
                            Me.txtBox2.DataBindings.Remove(Me.txtBox2.DataBindings("Text"))
                            Me.txtBox3.DataBindings.Remove(Me.txtBox3.DataBindings("Text"))
                            Me.txtBox4.DataBindings.Remove(Me.txtBox4.DataBindings("Text"))
                            Me.txtBox5.DataBindings.Remove(Me.txtBox5.DataBindings("Text"))
                            Me.txtBox1.DataBindings.Add(New Binding("Text", UberData.Staff, "ColleagueHoursPerWeek"))
                            Me.txtBox2.DataBindings.Add(New Binding("Text", UberData.Staff, "ColleagueHourlyRate"))
                            Me.txtBox3.DataBindings.Add(New Binding("Text", UberData.Staff, "ColleagueDateJoined"))
                            Me.txtBox4.DataBindings.Add(New Binding("Text", UberData.Staff, "ColleagueOnHoliday"))
                            Me.txtBox5.DataBindings.Add(New Binding("Text", UberData.Staff, "ColleagueUpcomingHoliday"))
                        End If
                    End If
                End If
            End If
        End Sub
    I'm guessing you'd prefer to view the code, so if you're interested please reply and I will provide you with it. Thanks for reading.

    Edit: I forgot to say. Payment will be made via PayPal.
    Last edited by ShaunC193; Nov 18th, 2011 at 10:03 PM.

  2. #2
    PowerPoster stanav's Avatar
    Join Date
    Jul 2006
    Location
    Providence, RI - USA
    Posts
    9,290

    Re: [2008] Databindings Problem - $10 to the Person to Solve it!

    Rule # 1: Don't offer $ for help in this forum. If you want to pay someone to help you write code (or even write the code for you), there are other places you can post your request, rentacoder.com for example. Giving appropriate ratings to those who have helped you is the better way to say "thank you".

    As for your problem, about the tabl control, is it a faked one? How does it work? At a glance of your code, it does look like you created a faked tab control, that is, you have a single panel with labels and textboxes on it and a few buttons. When a button clicks, you change and the background color/image the label's text to create the effect of a different tab. If this is what you're doing then it only gets you into trouble, especially when you use databindings (as you've already found out).

    Why can't you use a true tabcontrol? That would've solved your problem.
    Let us have faith that right makes might, and in that faith, let us, to the end, dare to do our duty as we understand it.
    - Abraham Lincoln -

  3. #3

    Thread Starter
    Lively Member
    Join Date
    Apr 2008
    Posts
    101

    Re: [2008] Databindings Problem - $10 to the Person to Solve it!

    I offered it because wherever I asked, nobody had a clue and few people replied. I've used other forums too. I thought a small amount of cash might be an incentive, yes, but ultimately it's just my way of saying thanks.

    As for the tab control, yes, I could use the default one. I went the extra mile and made a fake one, yes, and it works similarly to how you describe. I will consider using a proper one as a last resort. If I don't find any results within the next several days perhaps or don't solve it myself. The tab control looks nice, and while it isn't a requirement of the course, I want my software to stand out from the crowd.

    I understand functionality over eye candy is important, and I will go down that road if it's my only option. In the meantime, if anyone can help me solve this, I'd appreciate it. I'll provide the source as I said if anyone requests it.

  4. #4
    Super Moderator Shaggy Hiker's Avatar
    Join Date
    Aug 2002
    Location
    Idaho
    Posts
    40,106

    Re: [2008] Databindings Problem - $10 to the Person to Solve it!

    Strange way to fake the tabs. How about this solution:

    1) Make each pseudo-tab page a panel with the right number of textboxes and labels for that tab page.

    2) Either hide the panels that should not be shown, or set their Top property to somewhere well below the bottom of the screen (they are displayed, just not on the computer screen).

    3) When the user clicks on any tab, swap the proper panel into the viewing area, while hiding the others.

    This is how I write mobile apps, since forms take noticeable time to load on portable devices. You can find code examples in the mobile dev section of the forum under my name, but I haven't posted them in a couple years, so you'd have to search back a ways. It's basically a little state machine where selecting a tab would switch the state, then a single function would move out the current panel and move in the one that needs to be shown.

    Then you wouldn't have to bind/unbind the data. You'd have all the textboxes, and they could all be bound once, but only the ones on the currently displayed panel would be visible.

    By the way, $10 wouldn't even buy my lunch. Nobody who answers here is in it for the money.
    My usual boring signature: Nothing

  5. #5
    Hyperactive Member
    Join Date
    Jul 2007
    Location
    Iowa
    Posts
    298

    Re: [2008] Databindings Problem - $10 to the Person to Solve it!

    Quote Originally Posted by Shaggy Hiker
    Strange way to fake the tabs. How about this solution:

    1) Make each pseudo-tab page a panel with the right number of textboxes and labels for that tab page.

    2) Either hide the panels that should not be shown, or set their Top property to somewhere well below the bottom of the screen (they are displayed, just not on the computer screen).

    3) When the user clicks on any tab, swap the proper panel into the viewing area, while hiding the others.

    This!
    Tuber

    "I don't know the rules"

  6. #6

    Thread Starter
    Lively Member
    Join Date
    Apr 2008
    Posts
    101

    Re: [2008] Databindings Problem - $10 to the Person to Solve it!

    Hmm. I imagine it would require more system resources, but it certainly seems plausible. I'll give it a go ASAP.

  7. #7
    Super Moderator Shaggy Hiker's Avatar
    Join Date
    Aug 2002
    Location
    Idaho
    Posts
    40,106

    Re: [2008] Databindings Problem - $10 to the Person to Solve it!

    It would require more objects, which means more memory, but conserving memory is not....the object.
    My usual boring signature: Nothing

  8. #8
    PowerPoster stanav's Avatar
    Join Date
    Jul 2006
    Location
    Providence, RI - USA
    Posts
    9,290

    Re: [2008] Databindings Problem - $10 to the Person to Solve it!

    Also, if you decide to use multiple panels, there's a PanelManager class in VB.Net codebank (just saw it this morning) that may help making it easier to manage your panels.
    I'd use the standard tabcontrol and focus on writing reliable, efficient code instead of spending a lot of time making the UI look pretty but then the app runs like craps.
    Let us have faith that right makes might, and in that faith, let us, to the end, dare to do our duty as we understand it.
    - Abraham Lincoln -

  9. #9

    Thread Starter
    Lively Member
    Join Date
    Apr 2008
    Posts
    101

    Re: [2008] Databindings Problem - $10 to the Person to Solve it!

    Sorry for bumping, but it has been solved. Thanks to Shaggy Hiker for the idea. I also found this thread useful as I had some panel problems. I didn't use PanelManager but will certainly check it out in the future.

    Now, not only are there no issues with the tabs, but it runs more quickly too. Thanks.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width