Navigation dans deux tables connexes

Signaler
Messages postés
2
Date d'inscription
mercredi 11 avril 2012
Statut
Membre
Dernière intervention
12 avril 2012
-
Bonjour tout le monde,
je débute en Vb et je suis entraint de programmer une application
parent/ enfant.


En fait jŽai deux tables (region et office)
chacunes dans un datagrid.
seulement jŽai un souci:
lorsque je navigue sur la table region à lŽaide de deux boutons: suivant et précédent


je voudrais voir les enregistrements correspondant dans la table office.
voici le code:



Imports System.Windows.Forms

Public Class Form1
Inherits System.Windows.Forms.Form
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

Ds._REGION.Clear()
REGIONTableAdapter.Fill(Ds._REGION)
OFFICETableAdapter.Fill(Ds.OFFICE)

End Sub

Private Sub btnNext_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) _
Handles btnNext.Click

Me.BindingContext(Ds, "Region").Position = (Me.BindingContext(Ds, "Region").Position) + 1
PositionChanged()
End Sub
Private Sub btnPrev_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) _
Handles btnPrev.Click

Me.BindingContext(Ds, "Region").Position = (Me.BindingContext(Ds, "Region").Position) - 1
PositionChanged()
End Sub

Sub PositionChanged()
lblPos.Text = (((Me.BindingContext(Ds, "Region").Position.ToString _
+ " / ") _
+ (Me.BindingContext(Ds, "Region").Count.ToString)))
End Sub
Private Sub lblPos_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles lblPos.Click
Dim parentColumn As DataColumn = _
Ds.Tables("Region").Columns("ID")

Dim childColumn As DataColumn = Ds.Tables( _
"Office").Columns("REGID")



Dim relation As DataRelation
relation = New DataRelation("FK_OFFICE_REGID_ID ", parentColumn, childColumn)


Ds.Relations.Add(relation)

Dim SelectedID As String
SelectedID = lblPos.SelectedText

Dim drReg As DataRow
drReg = Ds._REGION.FindByID(SelectedID)

Dim droff As DataRow
Dim arroff() As DataRow
For Each relation In Ds.Tables("Office").ChildRelations

For Each droff In Ds.Tables("Region").Rows
arroff = droff.GetChildRows("relation")
Next droff
Next relation
End Sub
End Class

merci de me donner un coup de pouce