Bonjour,
en train de realiser un composant comboBox hérité du comboBox normal.
A la compile, tout se passe bien mais ca plante a l'appel.
A l'execution, ca plante ICI (voir ci dessous)
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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160 ' ' ' Composant NewComboBox ' ' Option Strict On <ToolboxBitmap(GetType(ComboBox))> _ Public Class NewComboBox Inherits System.Windows.Forms.ComboBox #Region " Définition de la classe publique " Public Class clsItem Private sItem As String Private lItemData As Long Sub New(ByVal lItemData As Long, ByVal sItem As String) MyClass.lItemData = lItemData MyClass.sItem = sItem End Sub Public Shadows ReadOnly Property ToString() As String Get Return sItem End Get End Property ReadOnly Property ItemData() As Long Get Return lItemData End Get End Property End Class #End Region #Region " Code généré par le Concepteur Windows Form " Public Sub New() MyBase.New() 'Cet appel est requis par le Concepteur Windows Form. InitializeComponent() 'Ajoutez une initialisation quelconque après l'appel InitializeComponent() End Sub 'La méthode substituée Dispose du UserControl pour nettoyer la liste des composants. Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean) If disposing Then If Not (components Is Nothing) Then components.Dispose() End If End If MyBase.Dispose(disposing) End Sub 'Requis par le Concepteur Windows Form Private components As System.ComponentModel.IContainer 'REMARQUE : la procédure suivante est requise par le Concepteur Windows Form 'Elle peut être modifiée en utilisant le Concepteur Windows Form. 'Ne la modifiez pas en utilisant l'éditeur de code. <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent() components = New System.ComponentModel.Container End Sub #End Region #Region " Variables privées " Dim CONSTColorForEqual As System.Drawing.Color = System.Drawing.Color.White Dim CONSTColorForModified As System.Drawing.Color = System.Drawing.Color.Khaki Dim m_InitialIndex As Integer = -1 #End Region #Region " Variables publiques " Public Event IndexModified(ByVal Modified As Boolean) #End Region #Region " Propriétés publiques " Public ReadOnly Property InitialIndex() As Integer Get Return m_InitialIndex End Get End Property Public ReadOnly Property IsModified() As Boolean Get If MyBase.SelectedIndex = m_InitialIndex Then Return False Else Return True End If End Get End Property Public Overrides Property SelectedIndex() As Integer Get Return MyBase.SelectedIndex End Get Set(ByVal Value As Integer) MyBase.SelectedIndex = Value m_InitialIndex = Value MyBase.BackColor = CONSTColorForEqual End Set End Property #End Region #Region " Méthodes publiques " Public Sub CancelChange() MyBase.SelectedIndex = m_InitialIndex End Sub Public Function SetIndexFromText(ByVal sMyText As String) As Long Dim i As Integer Dim clsMyClass As clsItem For i = 0 To MyBase.Items.Count - 1 If sMyText.Equals(MyBase.Items(i).ToString()) Then m_InitialIndex = i MyBase.SelectedIndex = i 'clsMyClass = MyBase.SelectedItem 'SetIndexFromText = clsMyClass.ItemData() Exit Function End If Next m_InitialIndex = -1 MyBase.SelectedIndex = -1 End Function #End Region #Region " Evenements " Protected Overrides Sub OnSelectedIndexChanged(ByVal e As System.EventArgs) If MyBase.SelectedIndex = m_InitialIndex Then MyBase.BackColor = CONSTColorForEqual RaiseEvent IndexModified(False) Else MyBase.BackColor = CONSTColorForModified RaiseEvent IndexModified(True) End If End Sub #End Region #Region " Code divers " Private Sub NewComboBox_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles MyBase.KeyPress If e.KeyChar = Microsoft.VisualBasic.ChrW(32) Then m_InitialIndex = -1 MyBase.SelectedIndex = -1 End If End Sub #End Region End Class
avec le motif suivant :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3 Dim itMyItem As BibControles.NewComboBox.clsItem itMyItem = ncbFarmResponsible.SelectedItem ' <<<<<< ICI lFarmResponsible = itMyItem.ItemData
Si quelqu'un peut m'aider à comprendfre ce qui se passe ...Informations supplémentaires : Le cast spécifié n'est pas valide.
Merci
Partager