怎么在datagridview的一行上添加右键菜单???
比如datagridview有一列属性性别 第一行是男 第二行是女我在第一行上点击鼠标右键会弹出菜单A!!在第二行上右键就出现菜单B
就是根据该行上某个属性来确定弹出的是哪个菜单
private void dataGridView1_CellMouseDown(object sender, DataGridViewCellMouseEventArgs e) { if (e.Button == MouseButtons.Right) { if (this.dataGridView1.SelectedCells[0].Value != null) { if (this.dataGridView1.SelectedCells[0].Value.ToString() == "男") { ContextMenuStrip contextMenuStrip1 = new System.Windows.Forms.ContextMenuStrip(); ToolStripMenuItem a1ToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); ToolStripMenuItem a2ToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); ToolStripMenuItem a3ToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); a1ToolStripMenuItem.Name = "a1ToolStripMenuItem"; a1ToolStripMenuItem.Size = new System.Drawing.Size(152, 22); a1ToolStripMenuItem.Text = "A1"; a2ToolStripMenuItem.Name = "a2ToolStripMenuItem"; a2ToolStripMenuItem.Size = new System.Drawing.Size(152, 22); a2ToolStripMenuItem.Text = "A2"; a3ToolStripMenuItem.Name = "a3ToolStripMenuItem"; a3ToolStripMenuItem.Size = new System.Drawing.Size(152, 22); a3ToolStripMenuItem.Text = "A3"; contextMenuStrip1.Items.AddRange(new System.Windows.Forms.ToolStripItem[] { a1ToolStripMenuItem, a2ToolStripMenuItem, a3ToolStripMenuItem}); contextMenuStrip1.Name = "contextMenuStrip1"; contextMenuStrip1.Size = new System.Drawing.Size(153, 92); this.dataGridView1.SelectedCells[0].ContextMenuStrip = contextMenuStrip1; } else if (this.dataGridView1.SelectedCells[0].Value.ToString() == "女") { ContextMenuStrip contextMenuStrip2 = new System.Windows.Forms.ContextMenuStrip(); ToolStripMenuItem b1ToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); ToolStripMenuItem b2ToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); ToolStripMenuItem b3ToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); b1ToolStripMenuItem.Name = "a1ToolStripMenuItem"; b1ToolStripMenuItem.Size = new System.Drawing.Size(152, 22); b1ToolStripMenuItem.Text = "B1"; b2ToolStripMenuItem.Name = "a2ToolStripMenuItem"; b2ToolStripMenuItem.Size = new System.Drawing.Size(152, 22); b2ToolStripMenuItem.Text = "B2"; b3ToolStripMenuItem.Name = "a3ToolStripMenuItem"; b3ToolStripMenuItem.Size = new System.Drawing.Size(152, 22); b3ToolStripMenuItem.Text = "B3"; contextMenuStrip2.Items.AddRange(new System.Windows.Forms.ToolStripItem[] { b1ToolStripMenuItem, b2ToolStripMenuItem, b3ToolStripMenuItem}); contextMenuStrip2.Name = "contextMenuStrip1"; contextMenuStrip2.Size = new System.Drawing.Size(153, 92); this.dataGridView1.SelectedCells[0].ContextMenuStrip = contextMenuStrip2; } } } }