ManuAntibes
Messages postés491Date d'inscriptionmardi 24 octobre 2000StatutMembreDernière intervention18 novembre 2021
-
1 mars 2019 à 08:13
ManuAntibes
Messages postés491Date d'inscriptionmardi 24 octobre 2000StatutMembreDernière intervention18 novembre 2021
-
1 mars 2019 à 13:17
Bonjour à tous,
je souhaite récup la valeur Tag, d'un Label (Classe_RTFLabel) créé dynamiquement, mais en passant par un ToolStripMenuItem.
Private RTFLabel As New List(Of Classe_RTFLabel)
Sub Planning_Prof(ByVal IdentifiantProf As Integer)
'Connexion à la base de donnée
Dim Rt As DataRowView
'Filtre par profs
Me.DataTable1TableAdapter.FillByProfesseur(Me.Database_CréaPlanningDataSet.DataTable1, IdentifiantProf)
For x = 0 To Me.DataTable1BindingSource.Count - 1
Dim DateCours, HeureDéb, HeureFin As Date
Dim ColonnePlanning, LignePlanning As Integer
Rt = CType(Me.DataTable1BindingSource.Item((x)), DataRowView)
' Création du label
Dim LabelPlanning As New Classe_RTFLabel
LabelPlanning.Font = New System.Drawing.Font("Microsoft Sans Serif", 10)
LabelPlanning.Dock = System.Windows.Forms.DockStyle.Fill
LabelPlanning.SelectionAlignment = HorizontalAlignment.Center
LabelPlanning.AppendItalic(CStr(Rt.Row.Item(8))) 'Matière
LabelPlanning.Text += vbNewLine
LabelPlanning.AppendBold(CStr(Rt.Row.Item(11))) 'Groupe Classe
LabelPlanning.Tag = (CStr(Rt.Row.Item(0))) 'Id Cours
LabelPlanning.ContextMenuStrip = ContextMenuStrip2 ' avec Modifier et Supprimer
End Sub
Private Sub ModifierToolStripMenuItem_Click(sender As System.Object, e As System.EventArgs) Handles ModifierToolStripMenuItem.Click
Dim _IdCours As integer
'Je ne sais pas quoi mettre ici
Dim ChildForm As New FormModif_SupCours
ChildForm.Show()
ChildForm.ActionModifier(_IdCours)
End Sub ' Modifi le RTFLabel dans la base Table_Cours
Whismeril
Messages postés18398Date d'inscriptionmardi 11 mars 2003StatutContributeurDernière intervention28 mai 2023623 1 mars 2019 à 09:35
Bonjour
Tu commences par caster sender en toolstripmenuitem, pour récupérer l’instance de contextmenu. (Propriété owner, owneritem ou parent , je ne sais plus et j’ai pas de quoi tester là)
Quand tu as le contextmenu il a aussi une propriété retournant quel object l’a affiché.
Tu castes cet object en Label et tu récupères le Tag
Private Sub ModifierToolStripMenuItem_Click(sender As System.Object, e As System.EventArgs) Handles ModifierToolStripMenuItem.Click
Dim objTSMI As ToolStripMenuItem
Dim objCMS As ContextMenuStrip
Dim objLabel As Classe_RTFLabel
objTSMI = CType(sender, ToolStripMenuItem)
objCMS = CType(objTSMI.Owner, ContextMenuStrip)
objLabel = CType(objCMS.SourceControl, Classe_RTFLabel)
Dim ChildForm As New FormModif_SupCours
ChildForm.Show()
ChildForm.ActionModifier(objLabel.Tag)
End Sub ' Modifi le RTFLabel dans la base Table_Cours