C sharp - Evento del click derecho

<<>>
 
Vista:
sin imagen de perfil

Evento del click derecho

Publicado por Angel (1 intervención) el 25/04/2024 10:57:04
Alguien sabe porque no me aparece el menu al presionar el click derecho con este codigo?

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
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
 
namespace Edit.TSMI_ModShowStorDat
{
    public partial class F_StorDat : Form
    {
        //private List<(string story, string height, string elevation, string master, string similar,
        //  string  spliceStor,string spliceHeight,Color color)> rowData = new List<(string story,
        //    string height, string elevation, string master, string similar,string spliceStor,
        //      string spliceHeight, Color color)>();
 
        private List<(string groupName,string comboboxValue, Color color)> rowData = new List<(string groupName, string comboBoxValue,
            Color color)>();
 
        public F_StorDat()
        {
            InitializeComponent();
 
            AgregarFilasDeEjemplo();
 
        }
 
        private void AgregarFilasDeEjemplo()
        {
            Dgv_StorData.Rows.Add("Valor 1");
            Dgv_StorData.Rows.Add("Valor 2");
            Dgv_StorData.Rows.Add("Valor 3");
 
        }
 
 
 
        private void Dgv_StorData_CellMouseClick(object sender, DataGridViewCellMouseEventArgs e)
        {
            if(e.Button == MouseButtons.Right)
            {
                ContextMenuStrip contextMenuStrip = new ContextMenuStrip();
                int posicion = Dgv_StorData.HitTest(e.X, e.Y).RowIndex;
                if(posicion > -1 )
                {
                    contextMenuStrip.Items.Add("Borrar", null);//.Name = "Borrar" + posicion;
                    contextMenuStrip.Items.Add("Mostrar",null);//Name = "Mostrar" + posicion;
                    Dgv_StorData.ContextMenuStrip = contextMenuStrip;
                    contextMenuStrip.Show(e.X, e.Y);
                    contextMenuStrip.ItemClicked += new ToolStripItemClickedEventHandler(menuClick);
                }
 
                // Dgv_StorData.ContextMenuStrip = contextMenuStrip;
                 //contextMenuStrip.Show(e.X, e.Y);
                // contextMenuStrip.ItemClicked += new ToolStripItemClickedEventHandler(menuClick);
                //this.Controls.Add(Dgv_StorData);
            }
        }
        private void menuClick(object sender, ToolStripItemClickedEventArgs e)
        {
            string id = e.ClickedItem.Name.ToString();
            if (id.Contains("Borrar"))
            {
                id = id.Replace("Borrar", "1");
            }
            if (id.Contains("Mostrar"))
            {
                id = id.Replace("Mostrar", "0");
                mostrar(int.Parse(id));
            }
        }
        private void mostrar (int idMostrar)
        {
            string res = "Celda1=" + Dgv_StorData.Rows[idMostrar].Cells[0].Value.ToString();
            MessageBox.Show(res);
        }
    }
Valora esta pregunta
Me gusta: Está pregunta es útil y esta claraNo me gusta: Está pregunta no esta clara o no es útil
0
Responder