1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82
|
Imports System.Data
Public Class Form1
Private bInit As Boolean
Private ds As DataSet
Private dvDirection As DataView
Private dvSousDirection As DataView
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
ds = New DataSet
bInit = True
' Ajout de la table
ds.Tables.Add("DIRECTIONS")
' Ajout des colonnes
' ------------------
AddColl("CODE", System.Type.GetType("System.String"), True)
AddColl("LIBELLE", System.Type.GetType("System.String"))
' Ajout de quelques lignes
AddRow("01", "Lib01")
AddRow("0101", "Lib01-01")
AddRow("0102", "Lib01-02")
AddRow("02", "Lib02")
AddRow("0201", "Lib02-01")
' Initialisation de la combobox direction
dvDirection = New DataView(ds.Tables("DIRECTIONS"))
dvDirection.RowFilter = "len(CODE) = 2"
cboDirection.DataSource = dvDirection
cboDirection.DisplayMember = "LIBELLE"
cboDirection.ValueMember = "CODE"
' Initialisation de la combobox sous-direction
dvSousDirection = New DataView(ds.Tables("DIRECTIONS"))
cboSousDirection.DataSource = dvSousDirection
cboSousDirection.DisplayMember = "LIBELLE"
cboSousDirection.ValueMember = "CODE"
bInit = False
If dvDirection.Count > 0 Then
cboDirection.SelectedIndex = 0
cboDirection_SelectedValueChanged(Nothing, Nothing)
End If
End Sub
' Fonction pour ajouter une colonne
Private Sub AddColl(ByVal pColumnName As String, ByVal pType As System.Type, Optional ByVal pUnique As Boolean = False)
Dim col As New DataColumn
With col
.DataType = pType
.ColumnName = pColumnName
.Unique = pUnique
End With
ds.Tables("DIRECTIONS").Columns.Add(col)
End Sub
' Ajout d'une ligne
Private Sub AddRow(ByVal pCode As String, ByVal pLibelle As String)
Dim newRow As DataRow
newRow = ds.Tables("DIRECTIONS").NewRow
newRow("CODE") = pCode
newRow("LIBELLE") = pLibelle
ds.Tables("DIRECTIONS").Rows.Add(newRow)
End Sub
' Changement de sélection dans la combobox Direction
Private Sub cboDirection_SelectedValueChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cboDirection.SelectedValueChanged
If Not bInit Then
dvSousDirection.RowFilter = "SUBSTRING(CODE,1,2) = " + cboDirection.SelectedValue + " and len(code) = 4"
End If
End Sub
End Class |
Partager