C# datagridview.cellpaintting事件刷新问题

wenhu420 2013-08-03 06:04:56
如何手动调用cellpaintting进行刷新呢?下面是一例,对datagridview的单元格进行重绘,因没有办法手动调用cellpaintting事件,所以,无法对单元格强制绘制,我试用invalidate()进行强行重绘,结果也不调用cellpaintting,而是调用onpaint.




using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace DatagridviewTest
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();

}

private void Form1_Load(object sender, EventArgs e)
{
this.dataGridView1.Rows.Add(10);
}

private void dataGridView1_CellPainting(object sender, DataGridViewCellPaintingEventArgs e)
{
if (e.RowIndex != -1)
{
e.Graphics.DrawString(e.RowIndex .ToString (), e.CellStyle.Font, new SolidBrush(Color.Red), e.CellBounds);
e.PaintContent(e.CellBounds);
e.Handled = true;
}


}


}
}
...全文
309 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
wenhu420 2013-08-03
  • 打赏
  • 举报
回复
可否举个例子吗?
xiaojunfei3 2013-08-03
  • 打赏
  • 举报
回复
你可以用js重新写html代码

110,571

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧