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 #MATLAB仿真#车辆换道路径规划
  • ¥15 java 操作 elasticsearch 8.1 实现 索引的重建
  • ¥15 数据可视化Python
  • ¥15 要给毕业设计添加扫码登录的功能!!有偿
  • ¥15 kafka 分区副本增加会导致消息丢失或者不可用吗?
  • ¥15 微信公众号自制会员卡没有收款渠道啊
  • ¥100 Jenkins自动化部署—悬赏100元
  • ¥15 关于#python#的问题:求帮写python代码
  • ¥20 MATLAB画图图形出现上下震荡的线条
  • ¥15 关于#windows#的问题:怎么用WIN 11系统的电脑 克隆WIN NT3.51-4.0系统的硬盘