我想你會想看看Faking alternative controls within a DataGridView control in Win Forms 2.0。它會外觀就像控件託管在DataGridView中,但實際上它恰好位於單元格上。我現在使用這兩個DateTimePickers和一個組合框取得了巨大的成功。從鏈接
示例代碼:
protected void dgCategory_CellClick(object sender, DataGridViewCellEventArgs e)
{
//set Date Picker to false when initially click on cell
if (dtPicker.Visible)
dtPicker.Visible = false;
if (e.ColumnIndex == 2)
{
//set date picker for category datagrid
dtPicker.Size = dgCategory.CurrentCell.Size;
dtPicker.Top = dgCategory.GetCellDisplayRectangle(e.ColumnIndex, e.RowIndex, true).Top;
dtPicker.Left = dgCategory.GetCellDisplayRectangle(e.ColumnIndex, e.RowIndex, true).Left;
if (!(object.Equals(Convert.ToString(dgCategory.CurrentCell.Value), "")))
dtPicker.Value = Convert.ToDateTime(dgCategory.CurrentCell.Value);
dtPicker.Visible = true;
}
}
private void dtPicker_ValueChanged(object sender, EventArgs e)
{
dgCategory.CurrentCell.Value = dtPicker.Value;
dtPicker.Visible = false;
}
不,它不會幫助解決他的問題。 – SLaks