Solved

C# BindingNavigator Control

Posted on 2006-07-19
4
3,486 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

On Demand Webinar: Networking for the Cloud Era

Ready to improve network connectivity? Watch this webinar to learn how SD-WANs and a one-click instant connect tool can boost provisions, deployment, and management of your cloud connection.

Question has a verified solution.

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

Article by: Najam
Having new technologies does not mean they will completely replace old components.  Recently I had to create WCF that will be called by VB6 component.  Here I will describe what steps one should follow while doing so, please feel free to post any qu…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
If you're a developer or IT admin, you’re probably tasked with managing multiple websites, servers, applications, and levels of security on a daily basis. While this can be extremely time consuming, it can also be frustrating when systems aren't wor…
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…

717 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