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.