Windows DataGridView中的GridView的RowDataBound等效事件 [英] GridView's RowDataBound equivalent event in Windows DataGridView

查看:327
本文介绍了Windows DataGridView中的GridView的RowDataBound等效事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述





Windows DataGridView中GridView的RowDataBound等效事件..

Hi,

GridView's RowDataBound equivalent event in Windows DataGridView..

推荐答案

 private void dataGridView1_CellFormatting(object sender, DataGridViewCellFormattingEventArgs e)
        {
//bala bala
        }


参考 -

1. winforms中的gridview rowdatabound事件? [ ^ ]

Refer -
1. gridview rowdatabound event in winforms?[^]
Quote:

DataGridView没有与ASP.NET中相同的事件处理。



您可以做的是处理RowsAdded事件,但请注意,当此事件触发时,可以添加多行。例如:



The DataGridView doesn't have the same event handling as in ASP.NET.

What you could do is handle RowsAdded event, but note that more than one row can be added when this event fires. An example:

private void dataGridView1_RowsAdded(object sender, DataGridViewRowsAddedEventArgs e)
{
    for (int i = e.RowIndex; i < e.RowCount + e.RowIndex; i++)
    {
        Console.WriteLine("Row " + i.ToString() + " added");
    }
}



此外,这个事件有点错误 - 当它是数据绑定时,它可能会多次触发行,但之后它的行为正确 - 当你向数据源添加一个新行时,它只被触发一次。



但是,我应该提一下(即使这不是您的原始问题),如果您在ASPX中使用此事件来处理输出格式,那么等效实际上就是CellFormatting事件 - 只要单元格需要显示它的值,就会调用此事件。


Also, this event is a bit 'buggy' - at the moment when it's databound it may fire more than once for each row, but afterwards it behaves correctly - when you add a new row to data source, it's fired only once.

But, I should probably mention (even if that's not your original question), that if you used this event in ASPX to handle output formatting, than here an equivalent would actually be CellFormatting event - this event is called whenever the cells needs to display it's value.



2. 用于DatagridView Windows窗体的RowDataBound [ ^ ]


我发现如果细胞不可见,即离屏幕的右边缘,那排不痛特惠。



我把代码链接到RowPrePaint事件。



I found that if the cell was not visible, ie off the right-hand edge of the screen, the row was not painted.

I've instead linked the code to RowPrePaint event.

private void dataGridView1_RowPrePaint ( object sender, DataGridViewRowPrePaintEventArgs e )
{
  if ( (bool)dataGridView1.Rows[e.RowIndex].Cells[userColumn].Value == true )
  {
    dataGridView1.Rows[e.RowIndex].DefaultCellStyle.BackColor = Color.MistyRose;
  }
}


这篇关于Windows DataGridView中的GridView的RowDataBound等效事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆