C# datagridview.cellpaintting事件刷新问题
如何手动调用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;
}
}
}
}
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;
}
}
}
}
...全文
相关推荐
C# 数据库增删查改及DataGridView刷新数据
数据库增删查改及DataGridView刷新数据
C#应用开发中DataGridView中添加按钮及按钮事件处理
C#应用开发中DataGridView中添加按钮及按钮事件处理
C# 异步刷新控件
异步刷新textbox和datagridview控件
c#实现dataGridview前显示行号
dataGridview控件前面是没有默认的行号的,要实现行号的显示需要自己的对控件进行重绘。本代码实现运用重绘方法使dataGridview显示行号。
C#里面DataGridView控件数据打印
使用DataGridView控件里面的数据打印,包含条码显示打印


