Relazioni tra due DataGrid !!!






Imports System
Imports System.Data
Imports System.Data.OleDb
'Imports System.Data.SqlClient

Imports System.Windows.Forms

#Region "Intestazione e Copyright "
'*********************************************************

'* XX XX PPPPPPPP *'********************************

'* XX XX PP PP *' **

'* XX XX PP PP *' BY Paolo Puglisi **

'* XXX PPPPPPPP *' Genio Software .Net **

'* XX XX PP *' vb6access@hotmail.com **

'* XX XX PP *' 10/12/2010 **

'* XX XX PP *'********************************

'********************************************************

'* Creazione del 10/12/2010 *

'********************************************************

' N N EEEEEEE TTTTTTTT

' NN N EE TT

' N N N EEEEEEE TT

' N N N EE TT

' N NN EE TT

' N N EEEEEEE TT

'********************************************************

'* Modifica del 10/12/2010 *

'********************************************************


#End Region


Public Class FrmDBComboGriglia
Friend WithEvents masterBindingSource As New BindingSource()
Friend WithEvents detailsBindingSource As New BindingSource()
Private Sub FrmDBComboGriglia_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
masterDataGridView.DataSource = masterBindingSource
detailsDataGridView.DataSource = detailsBindingSource
GetData()

' Resize the master DataGridView columns to fit the newly loaded data.

masterDataGridView.AutoResizeColumns()

' Configure the details DataGridView so that its columns automatically

' adjust their widths when the data changes.

detailsDataGridView.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.AllCells


End Sub
Private Sub GetData()
Try
' Specify a connection string. Replace the given value with a

' valid connection string for a Northwind SQL Server sample

' database accessible to your system.

' Dim StringaConn As String = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\Procedure\Radiologia\VbNetRadiologia\Database\Radiologia.mdb;Jet OLEDB:Database PassWord=;" '& "Jet OLEDB:Engine Type=5;"

Dim StringaConn As String = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\Procedure\Radiologia\VbNetRadiologia\Database\Radiologia.mdb;Persist Security Info=False"
Dim connectionString As String = StringaConn
'Dim connection As New OleDbConnection(connectionString)

Dim connection As OleDbConnection = New OleDbConnection(connectionString)
' Create a DataSet.

Dim data As New DataSet()
data.Locale = System.Globalization.CultureInfo.InvariantCulture
' Add data from the Amministratori table to the DataSet.

Dim masterDataAdapter As _
New OleDbDataAdapter("select ID, Tabella, Campo, Tipo from DBCombo", connection)
masterDataAdapter.Fill(data, "DBCombo")
' Add data from the DBComboItem table to the DataSet.

Dim detailsDataAdapter As _
New OleDbDataAdapter("select Id, IdDbCombo, Valore from DBComboItem", connection)
detailsDataAdapter.Fill(data, "DBComboItem")
' Establish a relationship between the two tables.

Dim relation As New DataRelation("DBComboDBComboItem", _
data.Tables("DBCombo").Columns("ID"), _
data.Tables("DBComboItem").Columns("IdDbCombo"))
data.Relations.Add(relation)
' Bind the master data connector to the DBCombo table.

masterBindingSource.DataSource = data
masterBindingSource.DataMember = "DBCombo"
' Bind the details data connector to the master data connector,

' using the DataRelation name to filter the information in the

' details table based on the current row in the master table.

detailsBindingSource.DataSource = masterBindingSource
detailsBindingSource.DataMember = "DBComboDBComboItem"
Catch ex As OleDbException
MessageBox.Show("To run this example, replace the value of the " & _
"connectionString variable with a connection string that is " & _
"valid for your system.")
End Try


End Sub





'################################## END FORM GeneraGenerate.vb ##################################

' (FrmDBComboGriglia.Form)

' By Paolo Puglisi (Alias Panzer Sherman) Mail to: vb6access@hotmail.com

' Generato e creato il 10/12/2010 8.58.27

'################################################################################################


End Class










( relazionitraduedatagrid.html )- by Paolo Puglisi - Modifica del 17/12/2023