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
Solved

How do I tie a bindingnavigator control to a datagrid without using the designer

Posted on 2006-11-20
3
862 Views
Last Modified: 2012-08-14
Ok, I'm trying to make a .net application which is very simple. The idea is that it starts with some opening arguments which tell it:

  1. Which db to open (the path)
  2. What query to use to get data
  3. What table it is to read from

So, what this means is that I need to actually change all the datasources and everything programmatically at run time.

I'm actually very new to .net, altho I have programmed in vb for about 7 months. The reason I'm doing this in .net is because vb6 doesn't have some features which my boss wants in the program.

Anyways, I have no idea how to do this in .net, and I've been trying to figure it out all day. It's very easy in vb6, I just set the datasource property. The best I can determine is that in order to do this I need to use a bindingnavigator control and a datagrid control.

Does anyone know how to do this through code only?
0
Comment
Question by:JeffreyDurham
  • 2
3 Comments
 

Author Comment

by:JeffreyDurham
ID: 17988302
This is what I ended up doing, it seems to work. If anyone knows of any particular way I might do this better please let me know. Thanks!

    Private bindingSource1 As New BindingSource

    private sub bindGrid()        
        dodatagridinit()
        Dim dbAdapter = New OleDbDataAdapter()
        Dim dtResults = New DataTable("Results")
        dbAdapter.Fill(dtResults, mydb.myRecordSet)
        Me.bindingSource1.DataSource = dtResults
        Me.BindingNavigator1.BindingSource = bindingSource1
        Me.mydatagrid.DataSource = bindingSource1
        Me.mydatagrid.AutoResizeColumns()
        dbAdapter = Nothing
        dtResults = Nothing
    End Sub

    Private Sub dodatagridinit()
        Me.mydatagrid.DataSource = Nothing
        Me.mydatagrid.ColumnHeadersVisible = True
        Me.mydatagrid.AllowDrop = False
        'Me.mydatagrid.AllowSorting = True
        'Me.mydatagrid.CaptionText = "These Records Will Be Used To Print Your Mailing Labels"
        'Me.mydatagrid.PreferredColumnWidth = 100
        'Me.mydatagrid.PreferredRowHeight = 20
    End Sub
0
 

Author Comment

by:JeffreyDurham
ID: 18031655
This is what I ended up doing. It worked Great. So that's that.

Public Sub bindTable()
        dodatagridinit()

        'Dim con As New OleDbConnection(mydb.myDbVars.myConnectStr)
        Dim conn As New OleDbConnection(mydb.myDbVars.myConnectStr)
        Dim myquerystr$ = CStr(mydb.myDbVars.myQueryStr)
        'myConnection.ConnectionString = myquerystr
        dbAdapter = New OleDb.OleDbDataAdapter(myquerystr, conn)
        mycb = New OleDbCommandBuilder(dbAdapter)
        ''original''    Dim cb As New OleDbCommandBuilder(dbAdapter)

        dbAdapter.Fill(dtResults)
        myConnection = conn
        'Me.lblTotal.Text = "Total: " &

        myConnection.Open()
        Me.bindingSource1.DataSource = dtResults
        Me.BindingNavigator1.BindingSource = bindingSource1
        Me.mydatagrid.DataSource = bindingSource1
        Me.mydatagrid.AutoResizeColumns()
        hideInvisColumns()
    End Sub
0
 

Accepted Solution

by:
PashaMod earned 0 total points
ID: 18036190
Closed, 125 points refunded.
PashaMod
Community Support Moderator
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

856 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