各位高手, 我在调整界面布局时,遇到这样一个问题, 在datagridView中有一个日期列,一个数字列,当我分别点击该列,会分别出现一个dateTimePicker, NumbericUpDown控件进行编辑。 我调整布局,将该dataGridView放入一个TableLayoutPanel后,这两个编辑控件就不出来了。不知何原因,寻求帮助,谢谢!
下面是代码
private void dataGridView_CellDoubleClick(object sender, DataGridViewCellEventArgs e)
{
if (e.RowIndex= this.dataGridView.RowCount) return;
// 设置坐标
if (e.ColumnIndex == 2)
{
Rectangle cellRectange = this.dataGridView.GetCellDisplayRectangle(e.ColumnIndex, e.RowIndex, false);
this.datePicker.Left = this.dataGridView.Left + cellRectange.X;
this.datePicker.Top = this.dataGridView.Top + cellRectange.Y;
this.datePicker.Width = cellRectange.Width;
this.datePicker.Height = cellRectange.Height;
// 值
if (this.dataGridView.Rows[e.RowIndex].Cells[e.ColumnIndex].Value == null || this.dataGridView.Rows[e.RowIndex].Cells[e.ColumnIndex].Value.ToString() == "")
{
this.datePicker.Value = DateTime.Now;
this.datePicker.Visible = true;
}
else
{
this.datePicker.Value = Convert.ToDateTime(this.dataGridView.Rows[e.RowIndex].Cells[e.ColumnIndex].Value);
this.datePicker.Visible = true;
}
}
else if (e.ColumnIndex == 5)
{
Rectangle cellRectange = this.dataGridView.GetCellDisplayRectangle(e.ColumnIndex, e.RowIndex, false);
this.numUpDown.Left = this.dataGridView.Left + cellRectange.X;
this.numUpDown.Top = this.dataGridView.Top + cellRectange.Y;
this.numUpDown.Width = cellRectange.Width;
this.numUpDown.Height = cellRectange.Height;
// 值
if (this.dataGridView.Rows[e.RowIndex].Cells[e.ColumnIndex].Value == null || this.dataGridView.Rows[e.RowIndex].Cells[e.ColumnIndex].Value.ToString() == "")
{
this.numUpDown.Value = 0;
this.numUpDown.Visible = true;
}
else
{
this.numUpDown.Value = (int)this.dataGridView.Rows[e.RowIndex].Cells[e.ColumnIndex].Value;
this.numUpDown.Visible = true;
}
}