Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / .NET Framework / New Users / August 2005

Tip: Looking for answers? Try searching our database.

Simple Q -  navigation not showing in bound textbox!

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Suzie - 14 Aug 2005 13:19 GMT
Hi!

I am newbie to Vb.net, so pls excuse if the Q seems silly! It is to
illustrate a problem i am having with navigating through a dataset table, and
having the bound text fields not showing the current record, but being stuck
on the first record permanently!

[If I create the connection, dataadapter and datset objects in design time,
and then bind the text property of the text boxes to the appropriate fields
in design time, then i do not have this problem. however,  my requirements
are to be able to do this in runtime - as illustrated in this example - and i
just cannot get it right]

I have a very simple form having two textbox fields showing the First Name
and Last Name and 4 buttons to navigate thru the records. I populate the
dataset in the formload event. The form code is shown below (am using VS.Net
2003):

Imports System.Data
Imports System.Data.SqlClient

Public Class Form1
   Inherits System.Windows.Forms.Form

   Private sqlconn As SqlConnection
   Private da As SqlDataAdapter
   Private ds As DataSet

   Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
       sqlconn = New SqlClient.SqlConnection
       sqlconn.ConnectionString = "Integrated Security=True;" & _
               "Data Source=LocalHost;Initial Catalog=Pubs;"
       sqlconn.Open()
       ds = New DataSet

       da = New SqlDataAdapter("Select au_lname, au_fname from authors",
sqlconn)
       da.Fill(ds, "authors")
       txtFName.DataBindings.Add("Text", ds.Tables("Authors"), "au_fname")
       txtLName.DataBindings.Add("Text", ds.Tables("Authors"), "au_lname")

   End Sub

   Private Sub btnFirst_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnFirst.Click
       Me.BindingContext(ds, "Authors").Position = 0
   End Sub

   Private Sub btnLast_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnLast.Click
       Me.BindingContext(ds, "Authors").Position = _
         Me.BindingContext(ds, "Authors").Count - 1
   End Sub

   Private Sub btnPrev_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnPrev.Click
       Me.BindingContext(ds, "Authors").Position -= 1
   End Sub

   Private Sub btnNext_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnNext.Click
       Me.BindingContext(ds, "Authors").Position += 1
   End Sub

End Class
Suzie - 14 Aug 2005 14:13 GMT
The form opens with the text boxes show the values relating to the first
record (as expected):
FName= Abraham
LName= Bennet

What i cant understand however is why pressing the navigation buttons does
not change the text in these textboxes - after all they are bound to the
underlying dataset in the form load.

When putting a breakpoint in the button handlers i can verify that the
dataset is indeed moving on through the records by using
? BindingContext(ds, "Authors").Position
in the immediate window.
It clearly shows that the position is NOT on 0 (the first record) - however
only the fiorst record's details show in the textbox.

WHAT AM I DOING WRONG or MISSING??

PLEASE HELP ME SOMEBODY!

What is even more incredulous is that if i place a datagrid on the form and
then
bind it in the form load event handler with the statements

       DataGrid1.DataSource = ds
       DataGrid1.DataMember = "Authors"

then it is plain to see the navigation buttons working as the records move
from one record to the next in the datagrid.
HOWEVER - the textboxes are still blisffully stuck on the first record thru
all of this!

HELP pls!  ;)

thks
Suzie
Suzie - 14 Aug 2005 14:19 GMT
The form opens with the text boxes show the values relating to the first
record (as expected):
FName= Abraham
LName= Bennet

What i cant understand however is why pressing the navigation buttons does
not change the text in these textboxes - after all they are bound to the
underlying dataset in the form load.

When putting a breakpoint in the button handlers i can verify that the
dataset is indeed moving on through the records by using
? BindingContext(ds, "Authors").Position
in the immediate window.
It clearly shows that the position is NOT on 0 (the first record) - however
only the fiorst record's details show in the textbox.

WHAT AM I DOING WRONG or MISSING??

PLEASE HELP ME SOMEBODY!

What is even more incredulous is that if i place a datagrid on the form and
then
bind it in the form load event handler with the statements

       DataGrid1.DataSource = ds
       DataGrid1.DataMember = "Authors"

then it is plain to see the navigation buttons working as the records move
from one record to the next in the datagrid.
HOWEVER - the textboxes are still blisffully stuck on the first record thru
all of this!

HELP pls!  ;)

thks
Suzie

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.