Jeanette Durham
asked on
How do I tie a bindingnavigator control to a datagrid without using the designer
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?
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?
ASKER
This is what I ended up doing. It worked Great. So that's that.
Public Sub bindTable()
dodatagridinit()
'Dim con As New OleDbConnection(mydb.myDbV ars.myConn ectStr)
Dim conn As New OleDbConnection(mydb.myDbV ars.myConn ectStr)
Dim myquerystr$ = CStr(mydb.myDbVars.myQuery Str)
'myConnection.ConnectionSt ring = myquerystr
dbAdapter = New OleDb.OleDbDataAdapter(myq uerystr, conn)
mycb = New OleDbCommandBuilder(dbAdap ter)
''original'' Dim cb As New OleDbCommandBuilder(dbAdap ter)
dbAdapter.Fill(dtResults)
myConnection = conn
'Me.lblTotal.Text = "Total: " &
myConnection.Open()
Me.bindingSource1.DataSour ce = dtResults
Me.BindingNavigator1.Bindi ngSource = bindingSource1
Me.mydatagrid.DataSource = bindingSource1
Me.mydatagrid.AutoResizeCo lumns()
hideInvisColumns()
End Sub
Public Sub bindTable()
dodatagridinit()
'Dim con As New OleDbConnection(mydb.myDbV
Dim conn As New OleDbConnection(mydb.myDbV
Dim myquerystr$ = CStr(mydb.myDbVars.myQuery
'myConnection.ConnectionSt
dbAdapter = New OleDb.OleDbDataAdapter(myq
mycb = New OleDbCommandBuilder(dbAdap
''original'' Dim cb As New OleDbCommandBuilder(dbAdap
dbAdapter.Fill(dtResults)
myConnection = conn
'Me.lblTotal.Text = "Total: " &
myConnection.Open()
Me.bindingSource1.DataSour
Me.BindingNavigator1.Bindi
Me.mydatagrid.DataSource = bindingSource1
Me.mydatagrid.AutoResizeCo
hideInvisColumns()
End Sub
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
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.DataSour
Me.BindingNavigator1.Bindi
Me.mydatagrid.DataSource = bindingSource1
Me.mydatagrid.AutoResizeCo
dbAdapter = Nothing
dtResults = Nothing
End Sub
Private Sub dodatagridinit()
Me.mydatagrid.DataSource = Nothing
Me.mydatagrid.ColumnHeader
Me.mydatagrid.AllowDrop = False
'Me.mydatagrid.AllowSortin
'Me.mydatagrid.CaptionText
'Me.mydatagrid.PreferredCo
'Me.mydatagrid.PreferredRo
End Sub