posts - 432,  comments - 40,  views - 55万
< 2025年3月 >
23 24 25 26 27 28 1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31 1 2 3 4 5
复制代码
  private void dgv_RowPrePaint(object sender, DataGridViewRowPrePaintEventArgs e)
        {
            if (infos[e.RowIndex].HaveDetails == "不存在")  //此条件会导致无限的刷新
            {
                dgv.Rows[e.RowIndex].Cells[11] = new DataGridViewTextBoxCell();
                dgv.Rows[e.RowIndex].Cells[11].Value = "";

            }
        }
复制代码
原因: new DataGridViewTextBoxCell() 程序导致 dgv_RowPrePaint事件重绘,所以就进入了无休止的 刷新
正确代码
复制代码
  private void dgv_RowPrePaint(object sender, DataGridViewRowPrePaintEventArgs e)
        {
            
            if (infos[e.RowIndex].HaveDetails == "不存在"&& dgv[11, e.RowIndex].GetType() == typeof(DataGridViewButtonCell))
            {
                dgv.Rows[e.RowIndex].Cells[11] = new DataGridViewTextBoxCell();
                dgv.Rows[e.RowIndex].Cells[11].Value = "";

            }
        }
复制代码

附添加按钮程序

   DataGridViewButtonColumn btn = new DataGridViewButtonColumn();
            btn.Name = "Details";
            btn.HeaderText = "查看详情";
            btn.DefaultCellStyle.NullValue = "";
            btn.Width = 45;
            dgv.Columns.Add(btn); 

按钮点击事件

复制代码
    private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e)
        {
            int index = dataGridView1.SelectedCells[0].RowIndex;
            var id = filesdt.Rows[index][0].ToString();

            if (this.dataGridView1.Columns[e.ColumnIndex].Name == "down")
            {
              
            }
            else if (this.dataGridView1.Columns[e.ColumnIndex].Name == "del")
            {

            }
        }
复制代码

 

posted on   小石头的一天  阅读(305)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 10年+ .NET Coder 心语 ── 封装的思维:从隐藏、稳定开始理解其本质意义
· 地球OL攻略 —— 某应届生求职总结
· 提示词工程——AI应用必不可少的技术
· Open-Sora 2.0 重磅开源!
· 周边上新:园子的第一款马克杯温暖上架
历史上的今天:
2016-11-25 c#在主窗体panel 容器内嵌入另一个窗体(子窗体)的实现
点击右上角即可分享
微信分享提示