Bonjour,

J'ai fais un UserControl qui a une propriété DataSource as dataTable
Après avoir initialiser cette propriété, j'aimerais que ma 2e propriété expose les champs de cette table (afin de déterminé si les champs seront visible et s'il y aura un alias a afficher plutôt que le nom du champ).

La gestion des nom de colonne et de l'affichage est fait à partir d'une autre classe. La 2e propriété expose cette classe.

Donc, en mode design, j'initialise mon DataSource. Ensuite, ma liste de champs apparait dans une propriété et il est possible de déterminer si le champ sera affiché ou non et s'il y aura un alias. Le problème est que lorsque je compile, le datasource reste en place, mais toute le paramétrage de champs que j'ai fais c'est réinitialiser avec les valeurs par défaut Pourquoi!!??

Alors voici mon code:
Code : Sélectionner tout - Visualiser dans une fenêtre à part
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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
 
Imports System.ComponentModel
 
<System.ComponentModel.DefaultBindingProperty("Valeur")> _
Public Class Selection
 
    Dim l_obj_dataSourceDisplay As BindingSource
    Dim l_obj_displayedFields As List(Of clsFields)
    Dim l_str_valueMember As String
 
    <Category("Paramètres")> _
    Public Property DataSourceDisplay() As BindingSource
        Get
            Return l_obj_dataSourceDisplay
        End Get
        Set(ByVal value As BindingSource)
            l_obj_dataSourceDisplay = value
            l_obj_displayedFields = getFields()
        End Set
    End Property
 
    Public Property Valeur() As String
        Get
            Return txtCode.Text
        End Get
        Set(ByVal value As String)
            txtCode.Text = value
            findPosition()
        End Set
    End Property
 
    <Category("Paramètres")> _
    <DesignerSerializationVisibility(DesignerSerializationVisibility.Content)> _
    Public Property ChampAffiches() As List(Of clsFields)
        Get
            Return l_obj_displayedFields
        End Get
        Set(ByVal value As List(Of clsFields))
            l_obj_displayedFields = value
        End Set
    End Property
 
    Private Function getFields() As List(Of clsFields)
        If DataSourceDisplay Is Nothing Then Return Nothing
 
        Dim l_str_fields As New List(Of clsFields)
 
        Dim l_obj_table As New DataTable
        If TypeOf DataSourceDisplay.DataSource Is DataSet Then
            l_obj_table = CType(DataSourceDisplay.DataSource, DataSet).Tables(DataSourceDisplay.DataMember)
        ElseIf TypeOf DataSourceDisplay.DataSource Is DataTable Then
            l_obj_table = DataSourceDisplay.DataSource
        End If
 
        For Each l_obj_colonne As DataColumn In l_obj_table.Columns
            l_str_fields.Add(New clsFields(l_obj_colonne.ColumnName, l_obj_colonne.ColumnName))
        Next
 
        Return l_str_fields
    End Function
 
    Public Class clsFields
        Private l_str_nom As String
        Private l_str_caption As String
        Private l_bln_visible As Boolean
 
        Public ReadOnly Property Nom() As String
            Get
                Return l_str_nom
            End Get
        End Property
 
        Public Property Caption() As String
            Get
                Return l_str_caption
            End Get
            Set(ByVal value As String)
                l_str_caption = value
            End Set
        End Property
 
        Public Property Visible() As Boolean
            Get
                Return l_bln_visible
            End Get
            Set(ByVal value As Boolean)
                l_bln_visible = value
            End Set
        End Property
 
        Public Sub New(ByVal p_str_fieldName As String, ByVal p_str_fieldAlias As String)
            l_str_nom = p_str_fieldName
            Caption = p_str_fieldAlias
            Visible = True
        End Sub
    End Class
End Class
Merci!