Visual Basic.NET
  Home arrow Visual Basic.NET arrow Page 2 - Using Data Sources with the DataGridView C...
ASP Free Forums 
.NET  
ASP  
ASP Code  
ASP.NET  
ASP.NET Code  
BrainDump  
C#  
Code Examples  
Database  
Database Code  
IIS  
Microsoft Access  
MS SQL Server  
Silverlight  
Visual Basic.NET  
Windows Scripting  
Windows Security  
XML  
Mobile Linux 
App Generation ROI 
IBM® developerWorks 
ASP Web Hosting  
ASP.NET Web Hosting 
Windows Web Hosting
 
Weekly Newsletter
 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid 
Request Media Kit
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
VISUAL BASIC.NET

Using Data Sources with the DataGridView Control
By: Murach Publishing
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 4 stars4 stars4 stars4 stars4 stars / 8
    2006-11-09

    Table of Contents:
  • Using Data Sources with the DataGridView Control
  • How to generate a DataGridView control from a data source
  • How to edit the properties of a DataGridView control
  • How to edit the columns of a DataGridView control
  • A Product Maintenance application that uses a DataGridView control

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article
     
     
    ADVERTISEMENT


    Using Data Sources with the DataGridView Control - How to generate a DataGridView control from a data source


    (Page 2 of 5 )

    By default, if you drag a table from the Data Sources window onto a form, Visual Studio adds a DataGridView control to the form and binds it to the table as shown in figure 14-6. This creates a DataGridView control that lets you browse all the rows in the table as well as add, update, and delete rows in the table. To provide this functionality, Visual Studio adds a toolbar to the top of the form that provides navigation buttons along with Add, Delete, and Save buttons.

    To bind a DataGridView control to a table, Visual Studio uses a technique called complex data binding. This just means that the bound control is bound to more than one data element. The DataGridView control in this figure, for example, is bound to all the rows and columns in the Products table.

    When you generate a DataGridView control from a data source, Visual Studio also adds four additional objects to the Component Designer tray at the bottom of the Form Designer. First, the DataSet object defines the dataset that contains the Products table. Second, the TableAdapter object provides commands that can be used to work with the Products table in the database. Third, the BindingSource object specifies the data source (the Products table) that the controls are bound to, and it provides functionality for working with the data source. Finally, the BindingNavigator defines the toolbar that contains the controls for working with the data source.

    Before I go on, I want to point out that the TableAdapter object is similar to the DataAdapter object you learned about in the previous chapter. However, it can only be created by a designer. In addition, it has a built-in connection and, as you’ll see later in this chapter, it can contain more than one query.

    I also want to mention that, in general, you shouldn’t have any trouble figuring out how to use the binding navigator toolbar. However, you may want to know that if you click the Add button to add a new row and then decide you don’t want to do that, you can click the Delete button to delete the new row. However, there’s no way to cancel out of an edit operation. Because of that, you may want to add a button to the toolbar that provides this function. You can learn how to add buttons to a toolbar in the next chapter.

    A form after the Products table has been dragged onto it

    The controls and objects that are created when you drag a data source to a form

    Control/object

    Description

    DataGridView control

    Displays the data from the data source in a grid.

    BindingNavigator control

    Defines the toolbar that can be used to navigate, add, update, and delete rows in the DataGridView control.

    BindingSource object

    Identifies the data source that the controls on the form are bound to and provides functionality for working with the data source.

    DataSet object

    Provides access to all of the tables, views, stored procedures, and functions that are available to the project.

    TableAdapter object

    Provides the commands that are used to read and write data to and from the specified table in the database.

    Description

    • To bind a DataGridView control to a table in a dataset, just drag the table from the Data Sources window onto the form. Then, Visual Studio automatically adds a DataGridView control to the form along with the other controls and objects it needs to work properly. Because the DataGridView control is bound to the table, it can be referred to as a bound control.
    • To bind a DataGridView control to a data table, Visual Studio uses a technique called complex data binding. This means that the control is bound to more than one data element, in this case, all the rows and columns in the table.

    Figure 14-6.   How to generate a DataGridView control from a data source

    More Visual Basic.NET Articles
    More By Murach Publishing


       · This article is an excerpt from the book "Murach's Visual Basic 2005," published by...
     

    Buy this book now. This article is excerpted from chapter 14 of the book Murach's Visual Basic 2005, written by Anne Boehm (Murach, 2006; ISBN: 1890774383). Check it out today at your favorite bookstore. Buy this book now.

    VISUAL BASIC.NET ARTICLES

    - User-defined Functions using Visual Basic Ap...
    - Understanding Object Binding in VBA
    - Mastering the Message Box
    - Testing a Windows Forms Application
    - Using Visual Basic.NET Features to Code a Wi...
    - Correcting Code in a Windows Forms Applicati...
    - Write Readable Code and Comments for Windows...
    - How to Code and Test a Windows Forms Applica...
    - Adding Features to a Windows Forms Applicati...
    - How to Design a Windows Forms Application
    - LINQ to XML Programming Using Visual Basic.N...
    - Understanding Delegates using Visual Basic.N...
    - Create a Sudoku Puzzle Generator using VB.NET
    - Entity Creation and Messaging in a VB.NET Te...
    - Movement and Player Statistics in a VB.NET T...





    © 2003-2009 by Developer Shed. All rights reserved. DS Cluster 3 Hosted by Hostway
    Stay green...Green IT