protected virtual void ShowDropDown()
{
Point p = this.EditingTable.PointToScreen(this.TextBox.Location);
p.Y += this.TextBox.Height + 1;
Rectangle screenBounds = Screen.GetBounds(p);
if (p.Y + this.dropDownContainer.Height > screenBounds.Bottom)
{
p.Y -= this.TextBox.Height + this.dropDownContainer.Height + 1;
}
if (p.X + this.dropDownContainer.Width > screenBounds.Right)
{
ICellRenderer renderer = this.EditingTable.ColumnModel.GetCellRenderer(this.EditingCellPos.Column);
int buttonWidth = ((DropDownCellRenderer) renderer).ButtonWidth;
p.X = p.X + this.TextBox.Width + buttonWidth - this.dropDownContainer.Width;
}
this.dropDownContainer.Location = p;
this.parentForm.AddOwnedForm(this.dropDownContainer);
this.activationListener.AssignHandle(this.parentForm.Handle);
this.dropDownContainer.ShowDropDown();
this.dropDownContainer.Activate();
// A little bit of fun. We've shown the popup,
// but because we've kept the main window's
// title bar in focus the tab sequence isn't quite
// right. This can be fixed by sending a tab,
// but that on its own would shift focus to the
// second control in the form. So send a tab,
// followed by a reverse-tab.
// Send a Tab command:
NativeMethods.keybd_event((byte) Keys.Tab, 0, 0, 0);
NativeMethods.keybd_event((byte) Keys.Tab, 0, KeyEventFFlags.KEYEVENTF_KEYUP, 0);
// Send a reverse Tab command:
NativeMethods.keybd_event((byte) Keys.ShiftKey, 0, 0, 0);
NativeMethods.keybd_event((byte) Keys.Tab, 0, 0, 0);
NativeMethods.keybd_event((byte) Keys.Tab, 0, KeyEventFFlags.KEYEVENTF_KEYUP, 0);
NativeMethods.keybd_event((byte) Keys.ShiftKey, 0, KeyEventFFlags.KEYEVENTF_KEYUP, 0);
}