473,830 Members | 2,156 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

VS2005,VB,Bindi ngNavigator: programmaticall y moving to record

As you can tell, I am new to VS.net.

I have a VB project with a defined data source pointing to a table in a ..mdb file.-- The associated fields are displayed in textboxes using the tableBindingSou rce. There is also an associated BindingNavigato r. The table's primary key is a field called 'who'. I have a valid value for 'who' and want to set the Navigator to the record that contains this value so the fields are displayed in the associated textboxes. The dataset is loaded with all records during FormLoad event.

The program's tray contains DataSettable, tableBindingSou rce, tableTableAdapt er, BindingNavigato r.

I tried tableBindingSou rce.Find("who", swho) - this doesn't seem to do anything. swho is a string containing a known valid value.

How do I accomplish this?

Also, if data is edited in the textboxes, I want to save the changes to the mdb file - how do I do that?

Same with Adding & Deleting records.

One other question - var = BindingNavigato r.MoveNextItem does not advance the Navigator. How to do this?

Appreciate the help ... Thank you.

Dale Sampson

Nov 4 '06 #1
7 27843
This is a lot of questions with complex answers.
I'll take a stab at some of them.

The find method returns an integer that points
to the position of the record you're looking for.
If it finds it, you need to change position to
that record.

Dim index as Integer = myBindingSource .Find("field",t xtField.Text)
If Index <-1 Then
'it was found, change position to that record
myBindingSource .Position = index
End If

On your binding navigator, if the buttons contained
therein don't work, make sure the [DataSource]
property is filled in and points to the right data source.

As for updating the database, it depends on if you're
using stored procedures, writing your own queries, etc.
Changes made on the screen will change the underlying
dataset, but will not be written back to the original
data source unless you specifically write that code.

As for positioning, I don't think you can invoke the
methods on the binding navigator. Instead of doing
that, modify the position property of the binding
source:

myBindingSource .Position += 1

or just do this: myBindingSource .MoveNext

I recommend that you check out "Data Binding with
Windows Forms 2.0" by Brian Noyes. It's written for
C#, but the downloadable code is available in both
C# and VB.

Good luck. Hope this helps.

Robin S.
"Dale Sampson" <da********@new sgroups.nospamw rote in message news:ef******** ******@TK2MSFTN GP04.phx.gbl...
As you can tell, I am new to VS.net.

I have a VB project with a defined data source pointing to a table in a .mdb file.-- The associated fields are displayed in textboxes using the tableBindingSou rce. There is also an associated BindingNavigato r. The table's primary key is a field called 'who'. I have a valid value for 'who' and want to set the Navigator to the record that contains this value so the fields are displayed in the associated textboxes. The dataset is loaded with all records during FormLoad event.

The program's tray contains DataSettable, tableBindingSou rce, tableTableAdapt er, BindingNavigato r.

I tried tableBindingSou rce.Find("who", swho) - this doesn't seem to do anything. swho is a string containing a known valid value.

How do I accomplish this?

Also, if data is edited in the textboxes, I want to save the changes to the mdb file - how do I do that?

Same with Adding & Deleting records.

One other question - var = BindingNavigato r.MoveNextItem does not advance the Navigator. How to do this?

Appreciate the help ... Thank you.

Dale Sampson

Nov 6 '06 #2
Hi Dale,

Firstly, a common walkthrough of using DataSet, BindingSource and
BindingNavigato r in a WinForms application is like below.

1. Add DataSet into the project. To do this, go to Project|Add New Item
menu and select DataSet in the 'Add New Item' window.

2. Add a connection to the database you'd like to use in the Server
Explorer. Scroll to the table you want to use in the Server Explorer and
drag it onto the DataSet in the designer. This will add a DataTable and a
corresponding TableAdapter (you could use the auto-generated TableAdapter
to retrieve data from DB into DataTable and save the data back to DB).

3. Add an instance of the DataSet, BindingSource and BindingNavigato r onto
the form. Add some controls onto the form to display data.

4. Set the BindingSource instance's DataSource property to the DataSet
instance and the BindingSource instance's DataMember property to the
datatable name.

5. Set the BindingNavigato r instance's BindingSource property to the
BindingSource instance.

6. Bind the controls on the form to the BindingSource instance.

7. Fill the DataSet in the form's Load event handler.

Build and run the program. When you click the 'move next' or 'move
previous' button in the BindingNavigato r control, the record currently
displayed in the controls is changed. In fact, the BindingNavigato r control
navigates the records by changing the Position property of its underlying
BindingSource object. In order to change the current row by code, we set
the Position property of the BindingSource object.

So as for your first question, since you have found out the index of the
row by calling the BindingSource.F ind method, you should set the
BindingSource.P osition to the index to navigate to this row.

As for your second question, call the BindingSource.E ndEdit method to apply
pending changes to the underlying data source first. Then, if the datatable
has a corresponding TableAdapter, you could call the Update method of the
TableAdapter object to save the data back to DB. Otherwise, you need to
write an update SQL statement and execute it using a SqlCommand object to
save the data to DB. I prefer the first option, which is more convenient.

As for your third question, as I have mentioned above, set the Position
property of the BindingSource instance. BindingNavigato r.MoveNextItem
returns the 'move next' ToolStripItem.

Hope this helps.
If you have anything unclear, please feel free to let me know.
Sincerely,
Linda Liu
Microsoft Online Community Support

=============== =============== =============== =====
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscripti...ult.aspx#notif
ications.

Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscripti...t/default.aspx.
=============== =============== =============== =====

This posting is provided "AS IS" with no warranties, and confers no rights.

Nov 6 '06 #3
Hi Dale,

How about the problem now? Is everything clear now?

If you have anything unclear, please feel free to let me know.

Thank you for using our MSDN Managed Newsgroup Support Service!
Sincerely,
Linda Liu
Microsoft Online Community Support

Nov 8 '06 #4
Thank you RobinS & Linda - I appreciate the help.

yes - the info you've provided has helped & I am to navigate the database & position as needed.

A related question.

As you pointed out, edits to the data are not saved until calls to the underlying bindingsource & tableadapter are called. For this purpose, I've added a Save button that does this & added a handler to trap the fields text_changed event to make the user aware of a pending change & enable Save. That works ok.

I haven't figure out a way to handle the case where the user decided NOT to save the changes. E.g., uses move_next _record or does a new search without clicking Save. In this case, I would like to 'roll back' the change i.e., have the original text displayed if the user goes back to the 'edited' but unsaved record. Can you point me to documentation or make suggestions about how I might accomplish this?

Thank you,

--
Dale Sampson
http://www.dalesplace.net
"Dale Sampson" <da********@new sgroups.nospamw rote in message news:ef******** ******@TK2MSFTN GP04.phx.gbl...
As you can tell, I am new to VS.net.

I have a VB project with a defined data source pointing to a table in a .mdb file.-- The associated fields are displayed in textboxes using the tableBindingSou rce. There is also an associated BindingNavigato r. The table's primary key is a field called 'who'. I have a valid value for 'who' and want to set the Navigator to the record that contains this value so the fields are displayed in the associated textboxes. The dataset is loaded with all records during FormLoad event.

The program's tray contains DataSettable, tableBindingSou rce, tableTableAdapt er, BindingNavigato r.

I tried tableBindingSou rce.Find("who", swho) - this doesn't seem to do anything. swho is a string containing a known valid value.

How do I accomplish this?

Also, if data is edited in the textboxes, I want to save the changes to the mdb file - how do I do that?

Same with Adding & Deleting records.

One other question - var = BindingNavigato r.MoveNextItem does not advance the Navigator. How to do this?

Appreciate the help ... Thank you.

Dale Sampson

Nov 8 '06 #5
Hi Dale,

Thank you for your response.

Let's say that we have some controls, e.g. TextBox, ComboBox and etc on the
form to display a row in the data source at one time. If you edit the data
in the controls and move to the next row, the EndEdit method of the
BindingSource is called internally, which applies the pending changes to
the underlying data source.

If you'd like to cancel the changes, you could use the CancelEdit method of
the BindingSource to do it.

If you are using your own buttons to navigate among the rows by changing
the BindingSource instance's Position property, you call the BindingSoruce
instance's CancelEdit method before changing the BindingSource instance's
Position property.

If you are using a BindingNavigato r control to do the navigating, you could
derive a new control from BindingNavigato r class and override the
OnItemChecked method in the new control to call the CancelEdit method of
BindingSource.

The following is the sample code of the derived class.

Imports System.Windows. Forms

Public Class ExtBindingNavig ator
Inherits BindingNavigato r

Public Sub New()
End Sub

Public Sub New(ByRef bs As BindingSource)
MyBase.New(bs)
End Sub

Protected Overrides Sub OnItemClicked(B yVal e As
System.Windows. Forms.ToolStrip ItemClickedEven tArgs)

If (e.ClickedItem. Name = Me.MovePrevious Item.Name Or
e.ClickedItem.N ame = Me.MoveNextItem .Name Or _
e.ClickedItem.N ame = Me.MoveFirstIte m.Name Or
e.ClickedItem.N ame = Me.MoveLastItem .Name) Then

Me.BindingSourc e.CancelEdit()
End If

MyBase.OnItemCl icked(e)

End Sub

End Class

Build the project and add an instance of the ExtBindingNavig ator onto the
form and set its BindingSource property to the BindingSource instance on
the form.

Hope this helps.
If you have anything unclear, please feel free to let me know.
Sincerely,
Linda Liu
Microsoft Online Community Support

=============== =============== =============== =====
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscripti...ult.aspx#notif
ications.

Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscripti...t/default.aspx.
=============== =============== =============== =====

This posting is provided "AS IS" with no warranties, and confers no rights.

Nov 9 '06 #6
Linda,

Thank you - I'll try this out tomorrow & if any problem, I'll post again.

Dale

"Linda Liu [MSFT]" <v-****@online.mic rosoft.comwrote in message
news:nI******** ******@TK2MSFTN GXA01.phx.gbl.. .
Hi Dale,

Thank you for your response.

Let's say that we have some controls, e.g. TextBox, ComboBox and etc on
the
form to display a row in the data source at one time. If you edit the data
in the controls and move to the next row, the EndEdit method of the
BindingSource is called internally, which applies the pending changes to
the underlying data source.

If you'd like to cancel the changes, you could use the CancelEdit method
of
the BindingSource to do it.

If you are using your own buttons to navigate among the rows by changing
the BindingSource instance's Position property, you call the BindingSoruce
instance's CancelEdit method before changing the BindingSource instance's
Position property.

If you are using a BindingNavigato r control to do the navigating, you
could
derive a new control from BindingNavigato r class and override the
OnItemChecked method in the new control to call the CancelEdit method of
BindingSource.

The following is the sample code of the derived class.

Imports System.Windows. Forms

Public Class ExtBindingNavig ator
Inherits BindingNavigato r

Public Sub New()
End Sub

Public Sub New(ByRef bs As BindingSource)
MyBase.New(bs)
End Sub

Protected Overrides Sub OnItemClicked(B yVal e As
System.Windows. Forms.ToolStrip ItemClickedEven tArgs)

If (e.ClickedItem. Name = Me.MovePrevious Item.Name Or
e.ClickedItem.N ame = Me.MoveNextItem .Name Or _
e.ClickedItem.N ame = Me.MoveFirstIte m.Name Or
e.ClickedItem.N ame = Me.MoveLastItem .Name) Then

Me.BindingSourc e.CancelEdit()
End If

MyBase.OnItemCl icked(e)

End Sub

End Class

Build the project and add an instance of the ExtBindingNavig ator onto the
form and set its BindingSource property to the BindingSource instance on
the form.

Hope this helps.
If you have anything unclear, please feel free to let me know.
Sincerely,
Linda Liu
Microsoft Online Community Support

=============== =============== =============== =====
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscripti...ult.aspx#notif
ications.

Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscripti...t/default.aspx.
=============== =============== =============== =====

This posting is provided "AS IS" with no warranties, and confers no
rights.

Nov 9 '06 #7
Linda,

I had a chance to try out your suggestion & it works nicely. You've also
improved my understanding of VB.net & I'll keep in mind using inheritance to
tailor a control's / classes' events.

Just for others info: Public Sub New(ByRef bs As BindingSource) should read
As BindingNavigato r

Thank you again for all your help!

Best regards,

--
Dale Sampson
http://www.dalesplace.net

"Linda Liu [MSFT]" <v-****@online.mic rosoft.comwrote in message
news:nI******** ******@TK2MSFTN GXA01.phx.gbl.. .
Hi Dale,

Thank you for your response.

Let's say that we have some controls, e.g. TextBox, ComboBox and etc on
the
form to display a row in the data source at one time. If you edit the data
in the controls and move to the next row, the EndEdit method of the
BindingSource is called internally, which applies the pending changes to
the underlying data source.

If you'd like to cancel the changes, you could use the CancelEdit method
of
the BindingSource to do it.

If you are using your own buttons to navigate among the rows by changing
the BindingSource instance's Position property, you call the BindingSoruce
instance's CancelEdit method before changing the BindingSource instance's
Position property.

If you are using a BindingNavigato r control to do the navigating, you
could
derive a new control from BindingNavigato r class and override the
OnItemChecked method in the new control to call the CancelEdit method of
BindingSource.

The following is the sample code of the derived class.

Imports System.Windows. Forms

Public Class ExtBindingNavig ator
Inherits BindingNavigato r

Public Sub New()
End Sub

Public Sub New(ByRef bs As BindingSource)
MyBase.New(bs)
End Sub

Protected Overrides Sub OnItemClicked(B yVal e As
System.Windows. Forms.ToolStrip ItemClickedEven tArgs)

If (e.ClickedItem. Name = Me.MovePrevious Item.Name Or
e.ClickedItem.N ame = Me.MoveNextItem .Name Or _
e.ClickedItem.N ame = Me.MoveFirstIte m.Name Or
e.ClickedItem.N ame = Me.MoveLastItem .Name) Then

Me.BindingSourc e.CancelEdit()
End If

MyBase.OnItemCl icked(e)

End Sub

End Class

Build the project and add an instance of the ExtBindingNavig ator onto the
form and set its BindingSource property to the BindingSource instance on
the form.

Hope this helps.
If you have anything unclear, please feel free to let me know.
Sincerely,
Linda Liu
Microsoft Online Community Support

=============== =============== =============== =====
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscripti...ult.aspx#notif
ications.

Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscripti...t/default.aspx.
=============== =============== =============== =====

This posting is provided "AS IS" with no warranties, and confers no
rights.

Nov 9 '06 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
2982
by: chfran | last post by:
I have a form (continuous) that show me data from a table (not a query). I can only modify and move between the data of the first record. I cannot move to the 2nd, 3rd, or 85th record, only the first. I don't know if I've turned on something unintentionally or what. Any insights? chfran
6
4920
by: Matt | last post by:
I'm not entirely sure how to describe this issue. I have a number of ComboBoxes in my application which have their text properties bound to a field in a data set. The items loaded in the ComboBox are not data bound (they just use the built in collection property of the ComboBox), and they are all set to use the DropDownList style. When moving from record to record via a BindingNavigator or a DataGridView (in master/detail format), the text...
1
2556
by: Parasyke | last post by:
Thanks in advance... I need to on a subform in datasheet view to be able to, instead of delete a record, move that record to another table. I can if needed turn the subform into a continuous form emulating a datasheet view. Any clues on how to do this? Thanks! ... Dav
0
931
by: csharpa | last post by:
Hi, I have 2 tables a parent and a child. I want to insert value from Windows Form to DB(MSSQL) in VS2005. Although I’m sending data to both of them but the new record will be generated only in parent table but not child. At the first I thought that it is because the child does not receive the FK. But later when I tried to add FK manually(NOT parametric) I found that the new record will not be added. Although I set the seed value and...
3
1573
gregoryt2002
by: gregoryt2002 | last post by:
I need to search one of my database tables and move all the duplicate records into a new table. Is there an easy query to do this? Thanks Tom
1
1423
by: HUgradar | last post by:
Hi i have an access databse with one table at the moment. when a visitor comes onto site he is entered on to a form and the details saved in a table the table is shared on sharepoint so everyone can view who is on site. I want a feature which removes a person from the table once they have left the site? i have a check box which says left site? if they have the box is ticked is there anything i can do move the person from one table to...
1
1227
by: GWeber | last post by:
I am creating an inventory db in access and I want to be able to move a record to a different table when the location of where that asset is currently being stored is changed. I don't see a macro action that I can use and I was wondering is tehre was any VBA code that would work?? Any thoughts??
1
1530
by: Whiteeagle | last post by:
Hi all I have inherated a bit of a dilema and not sure about the correct way of solving the problem. The company I work for have 60 identical but seperate databases which are all in seperate folders on the network for the 60 offices that use them. I have taken over looking after these databases and supporting them. Each database have the same tables and forms but I would like to create a seperate database that will be able to show all...
0
3944
by: sincos | last post by:
Hello, First, sorry for my English, I hope you will understand me:) I'm new in using C Sharp and more with the bindingNavigator. What I would do is to simulate the button "add" (bindingnavigatorAddNewItem_Click) programmatically. Indeed, rather than either the user who clicks on this button, I will like to call it programmatically. What I do is: bindingNavigator.BindingSource = bindingSource; ... ... ...
0
10769
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10479
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10523
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10199
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9312
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7741
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5616
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5778
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3956
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.