我的Datagridview包含DateTimeColumn,它在滚动时与另一个下一行列重叠。我已将DatagridView属性设置为
AutoSizeColumnsMode:填充
AutoSizeRowsMode:AllCellsExceptheaders
AllowUserstoAddRows:True
但它告诉我以下结果。任何帮助都会很棒
我的代码
private void dataGridView4_CellClick(object sender, DataGridViewCellEventArgs e)
{
try
{
if (e.RowIndex != -1)
{
if (e.ColumnIndex == 1 || e.ColumnIndex == 2)
{
oDateTimePicker = new DateTimePicker();
dataGridView4.Controls.Add(oDateTimePicker);
oDateTimePicker.Format = DateTimePickerFormat.Short;
Rectangle oRectangle = dataGridView4.GetCellDisplayRectangle(e.ColumnIndex, e.RowIndex, true);
oDateTimePicker.Size = new Size(oRectangle.Width, oRectangle.Height);
oDateTimePicker.Location = new Point(oRectangle.X, oRectangle.Y);
oDateTimePicker.TextChanged += new EventHandler(dateTimePicker_OnTextChange);
oDateTimePicker.Visible = true;
}
}
}
catch (Exception E)
{
MessageBox.Show(E.ToString());
}
}
private void dateTimePicker_OnTextChange(object sender, EventArgs e)
{
dataGridView4.CurrentCell.Value = oDateTimePicker.Text.ToString();
}
答案 0 :(得分:1)
似乎不是使用真实的DataGridViewColumn
而是将DateTimePicker
上的某些DataGridView
对齐。
您可以创建自定义DateTimePicker
,而不是在DataGridView
上方对齐某些DataGridViewColumn
控件。
这是一个实现CalendarColumn
的好MSDN Example。