HighTechTalks DotNet Forums  

Simple Q - navigation not showing in bound textbox!

Dotnet Academic General Discussions microsoft.public.dotnet.academic


Discuss Simple Q - navigation not showing in bound textbox! in the Dotnet Academic General Discussions forum.



Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old   
Suzie
 
Posts: n/a

Default Simple Q - navigation not showing in bound textbox! - 08-14-2005 , 08:19 AM






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

Reply With Quote
  #2  
Old   
Suzie
 
Posts: n/a

Default RE: Simple Q - navigation not showing in bound textbox! - 08-14-2005 , 09:13 AM






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



Reply With Quote
  #3  
Old   
Suzie
 
Posts: n/a

Default Justy to explain a bit more ... - 08-14-2005 , 09:19 AM




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


Reply With Quote
Reply




Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.4
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.