liuxiangjun 2016-02-14 07:44 采纳率: 0%
浏览 3007
已结题

C# DataGridView列编辑控件显示问题

各位高手, 我在调整界面布局时,遇到这样一个问题, 在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;
            }
        }
  • 写回答

2条回答

  • zy__ 2016-02-14 08:18
    关注

    1)是不是当放入TableLayoutPanel后,在选则的时候,选中的是TableLayoutPanel。
    2)可以试试先去掉TableLayoutPanel,看看有什么现象。

    评论

报告相同问题?

悬赏问题

  • ¥15 delta降尺度计算的一些细节,有偿
  • ¥15 Arduino红外遥控代码有问题
  • ¥15 数值计算离散正交多项式
  • ¥30 数值计算均差系数编程
  • ¥15 redis-full-check比较 两个集群的数据出错
  • ¥15 Matlab编程问题
  • ¥15 训练的多模态特征融合模型准确度很低怎么办
  • ¥15 kylin启动报错log4j类冲突
  • ¥15 超声波模块测距控制点灯,灯的闪烁很不稳定,经过调试发现测的距离偏大
  • ¥15 import arcpy出现importing _arcgisscripting 找不到相关程序