[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.
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.
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.
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.
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!
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.
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.
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.
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. :thumb: