Results 1 to 3 of 3

Thread: Adding a binding navigator with code. VS2005

  1. #1

    Thread Starter
    Lively Member smilbuta's Avatar
    Join Date
    Apr 2005
    Location
    Orlando
    Posts
    104

    Adding a binding navigator with code. VS2005

    Hello all,

    I have a dataset used to populate a datagrid. I wish to bind a Binding navigator to the datagrid after its created.

    I know how to do it using the wizard and with almost no code but i want to do it code wise so i can see what happens in the background. (does that make sence?) here is my simple code.

    VB Code:
    1. Imports System.Data
    2. Imports System.Data.SqlClient
    3.  
    4.  
    5. Public Class Inventory
    6.  
    7.     'Dim objAdapter As New SqlDataAdapter
    8.     Dim objDataset As New DataSet
    9.  
    10.  
    11.  
    12.  
    13.     Private Function getConnectionString() As String
    14.         Return "***edited for Safety***"
    15.     End Function
    16.     Private Function getSqlString() As String
    17.         Return "SELECT * FROM EQ_Equipment"
    18.     End Function
    19.  
    20.     Private Sub Inventory_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    21.         'Dim sqlConnection As SqlConnection = New SqlConnection(getConnectionString)
    22.         Dim objAdapter As New SqlDataAdapter(getSqlString, getConnectionString)
    23.         Dim objdataset As New DataSet
    24.         objAdapter.Fill(objdataset, "inventory")
    25.  
    26.         dgvInventory.DataSource = objdataset
    27.         dgvInventory.DataMember = "inventory"
    28.  
    29.     End Sub
    30.  
    31.  
    32. End Class

  2. #2
    Frenzied Member circuits2's Avatar
    Join Date
    Sep 2006
    Location
    Kansas City, MO
    Posts
    1,027

    Re: Adding a binding navigator with code. VS2005

    A good way to learn how to code something manually is to use the wizard and then view the system generated code afterwards. That should give you a pretty good idea of what properties need to be set in order to successfully bind the Navigator.
    Show the love! Click (rate this post) under my name if I was helpful.

    My CodeBank Submissions: How to create a User Control | Move a form between Multiple Monitors (Screens) | Remove the MDI Client Border | Using Report Viewer with Visual Studio 2012 Express

  3. #3
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,222

    Re: Adding a binding navigator with code. VS2005

    You don't bind a BindingNavigator to a DataGridView. Those two objects know absolutely nothing about each other.

    1. Populate a DataTable with your data.
    2. Bind your DataTable to a BindingSource.
    3. Assign your BindingSource object to the BindingSource property of your BindingNavigator.

    Now, any actions you perform on the BindingNavigator will affect the data exposed through the BindingSource.

    4. Bind your BindingSource to your DataGridView.

    Now, the grid will display the data exposed through the BindingSource.

    The BindingSource is the centre of all this. The BindingNavigator affects the data in the BindingSource and the grid displays the data in the BindingSource. The BindingNavigator and the grid never meet.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width