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 请教:如何用postman调用本地虚拟机区块链接上的合约?
  • ¥15 为什么使用javacv转封装rtsp为rtmp时出现如下问题:[h264 @ 000000004faf7500]no frame?
  • ¥15 乘性高斯噪声在深度学习网络中的应用
  • ¥15 运筹学排序问题中的在线排序
  • ¥15 关于docker部署flink集成hadoop的yarn,请教个问题 flink启动yarn-session.sh连不上hadoop,这个整了好几天一直不行,求帮忙看一下怎么解决
  • ¥15 深度学习根据CNN网络模型,搭建BP模型并训练MNIST数据集
  • ¥15 C++ 头文件/宏冲突问题解决
  • ¥15 用comsol模拟大气湍流通过底部加热(温度不同)的腔体
  • ¥50 安卓adb backup备份子用户应用数据失败
  • ¥20 有人能用聚类分析帮我分析一下文本内容嘛