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)); } }
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))); }
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)