ToolStripMenuItem

Résolu
ManuAntibes Messages postés 491 Date d'inscription mardi 24 octobre 2000 Statut Membre Dernière intervention 18 novembre 2021 - 1 mars 2019 à 08:13
ManuAntibes Messages postés 491 Date d'inscription mardi 24 octobre 2000 Statut Membre Dernière intervention 18 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


le contextMenuStrip2 est mis sur ma form .

merci pour votre aide
Manu

2 réponses

Whismeril Messages postés 18398 Date d'inscription mardi 11 mars 2003 Statut Contributeur Dernière intervention 28 mai 2023 623
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
1
ManuAntibes Messages postés 491 Date d'inscription mardi 24 octobre 2000 Statut Membre Dernière intervention 18 novembre 2021 5
1 mars 2019 à 13:17
Salut

Tu m'as mis sur la piste, et j'ai fini par trouvé, ici
https://stackoverflow.com/questions/37700548/vb-net-get-the-control-that-is-used-to-show-the-contextmenu-strip

voici mon code final
 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
0