This repository has been archived on 2024-01-16. You can view files and clone it, but cannot push or open issues or pull requests.
custom-popup-demo/ComboBoxDemo/MainForm.cs

36 lines
1.2 KiB
C#

using System.Drawing;
using System.Windows.Forms;
namespace CustomPopupDemo
{
public partial class MainForm : Form
{
public MainForm()
{
InitializeComponent();
}
private void MainDataGridView_EditingControlShowing(object sender, DataGridViewEditingControlShowingEventArgs e)
{
// show only on "Code" column cells
if (dataGridViewDemo.CurrentCell.ColumnIndex != dataGridViewDemo.Columns["dgvColCode"].Index) {
return;
}
DataGridViewTextBoxEditingControl textBox = e.Control as DataGridViewTextBoxEditingControl;
Rectangle cellRect = dataGridViewDemo.GetCellDisplayRectangle(dataGridViewDemo.CurrentCell.ColumnIndex, dataGridViewDemo.CurrentCell.RowIndex, true);
// cell should be a textbox
if (textBox == null) {
return;
}
// display the popup below the cell
EmployeePicker popup = new EmployeePicker(textBox);
new DropDown(popup).Show((Control)sender, new Point(cellRect.Left, cellRect.Top + cellRect.Height));
popup.Focus();
}
}
}