Click here to Skip to main content
15,901,853 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I can't seem to figure out how to position my ContextMenuStrip below my dataGridViewCell. When I click the dataGridViewComboBoxCell I want my ContextMenuStrip to show right below the cell. Here's what I've done so far:

class MyDropDownList : DataGridViewComboBoxCell
{
   ContextMenuStrip dropDownList;

   public MyDropDownList()
   {
       dropDownList = new ContextMenuStrip();
       dropDownList.Items.Add("Hello World");
       dropDownList.Items.Add("Goodbye");
       dropDownList.Items.Add("Random stuff...");
   }

   protected override void OnMouseClick(DataGridViewCellMouseEventArgs e)
   {
       // ContextMenuStrip shows where the mouse
       // was clicked within the cell area...
       // I want the ContextMenuStrip to show 
       // right below the cell and to be aligned 
       // properly with the cell.

       dropDownList.Show(Cursor.Position.X, Cursor.Position.Y);

       // This wasn't even close!
       // dropDownList.Show(base.DataGridView.PointToScreen(e.Location));
   }
}


So basically I want the ContextMenuStrip to is act is my
DropDownList for the dataGridViewComboBoxCell
Posted
Updated 24-Apr-13 7:36am
v2
Comments
snorkie 24-Apr-13 13:30pm    
can you elaborate on what it is doing.
d.allen101 24-Apr-13 13:35pm    
I'm trying to show the ContextMenuStrip right below the cell when it's clicked.
d.allen101 24-Apr-13 13:42pm    
I'm using the MyDropDownList in place of DataGridViewComboBoxCell

1 solution

protected override void OnMouseClick(DataGridViewCellMouseEventArgs e)
        {
            Rectangle rect = DataGridView.GetCellDisplayRectangle(e.ColumnIndex, e.RowIndex, false);
            dropDownList.Show(DataGridView.PointToScreen(new Point(rect.Left, rect.Bottom)));
        }
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900