C# BindingNavigator Control

Posted on 2006-07-19
Last Modified: 2012-08-14
I have populated DateGridView control with following code:

DataTable dataTable = new DataTable();
SqlDataAdapter da = new SqlDataAdapter("select * from Customers", someConnectionString);
dataGridView1.DataSource = dataTable;

Now I would like to add BindingNavigator Control so that user can easily navigate, add or remove records.
How do I "linked" the two controls?
Question by:michellechan57
  • 2
  • 2

Accepted Solution

e1v earned 500 total points
ID: 17142028
If you have a BindingNavigator called bindingNavigator1 on your form, you can to this:

DataTable dataTable = new DataTable();
SqlDataAdapter da = new SqlDataAdapter("select * from Customers", someConnectionString);

BindingSource bindingSource = new BindingSource(dataTable, null);
dataGridView1.DataSource = bindingSource;
bindingNavigator1.BindingSource = bindingSource;


Author Comment

ID: 17142381
Hi e1v,

It works. Thanks. May I ask why the add and delete buttons in the BindingNavigator did not update the table when pressed (or should I ask as a new question)?

Expert Comment

ID: 17144222
Hi,  with "did not update the table " did you mean that dhe database did not get updated? To that you must explisit do a update and for that you need update, delete and insert-commands in your SqlDataAdapter.
Those can you create using SqlCommandBuilder like:

 SqlCommandBuilder sb = new SqlCommandBuilder(da);
            da.UpdateCommand = sb.GetUpdateCommand();
            da.DeleteCommand = sb.GetDeleteCommand();
            da.InsertCommand = sb.GetInsertCommand();

and then do
da.Update(dataTable); to write changes to the database.

All this you get for free when using drag-and-drop databinding with datasets, so for simple projects it might be worth looking into.

Author Comment

ID: 17146779

Featured Post

Enterprise Mobility and BYOD For Dummies

Like “For Dummies” books, you can read this in whatever order you choose and learn about mobility and BYOD; and how to put a competitive mobile infrastructure in place. Developed for SMBs and large enterprises alike, you will find helpful use cases, planning, and implementation.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Close form "before" open 3 40
converto datetime always changes format 9 37
Expression Evaluater 3 27
Get distinct values from excel or comm seperated file 4 27
Introduction This article series is supposed to shed some light on the use of IDisposable and objects that inherit from it. In essence, a more apt title for this article would be: using (IDisposable) {}. I’m just not sure how many people would ge…
This article aims to explain the working of CircularLogArchiver. This tool was designed to solve the buildup of log file in cases where systems do not support circular logging or where circular logging is not enabled
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …

803 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question