Solved

C# BindingNavigator Control

Posted on 2006-07-19
4
3,462 Views
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);
dataTable.Clear();
da.Fill(dataTable);
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?
0
Comment
Question by:michellechan57
  • 2
  • 2
4 Comments
 
LVL 6

Accepted Solution

by:
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);
dataTable.Clear();
da.Fill(dataTable);

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


0
 

Author Comment

by:michellechan57
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)?
0
 
LVL 6

Expert Comment

by:e1v
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.
0
 

Author Comment

by:michellechan57
ID: 17146779
Thanks.
0

Featured Post

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

Article by: Ivo
C# And Nullable Types Since 2.0 C# has Nullable(T) Generic Structure. The idea behind is to allow value type objects to have null values just like reference types have. This concerns scenarios where not all data sources have values (like a databa…
Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

758 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

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now