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,看看有什么现象。

    评论

报告相同问题?

悬赏问题

  • ¥50 永磁型步进电机PID算法
  • ¥15 sqlite 附加(attach database)加密数据库时,返回26是什么原因呢?
  • ¥88 找成都本地经验丰富懂小程序开发的技术大咖
  • ¥15 如何处理复杂数据表格的除法运算
  • ¥15 如何用stc8h1k08的片子做485数据透传的功能?(关键词-串口)
  • ¥15 有兄弟姐妹会用word插图功能制作类似citespace的图片吗?
  • ¥200 uniapp长期运行卡死问题解决
  • ¥15 latex怎么处理论文引理引用参考文献
  • ¥15 请教:如何用postman调用本地虚拟机区块链接上的合约?
  • ¥15 为什么使用javacv转封装rtsp为rtmp时出现如下问题:[h264 @ 000000004faf7500]no frame?