在GridView中的WinForms RowDataBound事件? [英] gridview rowdatabound event in winforms?

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

问题描述

在asp.net中我们可以处理GridView控件的RowDataBound事件。此事件在每一行添加到GridView。

in asp.net we can handle the RowDataBound event of the GridView control. this event fires when every row is added to the gridview.

我希望能够处理在WinForms应用程序在GridView这一事件,但我不能找到一个类似的活动。我的问题是什么是事件名称允许我做一样的RowDataBound在asp.net?

i want to be able to handle this event in the gridview in a winforms application but i cannot find a similar event. my question is what is the event name that allows me to do the same as RowDataBound in asp.net?

推荐答案

在DataGridView不具有相同的事件处理在ASP.NET。

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

你可以做的是处理 RowsAdded 事件,但请注意,多行可以加这个事件触发时。举个例子:

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");
    }
}

此外,本次活动是有点'马车' - 在这个时候它的数据绑定可能触发不止一次每行的时刻,但后来它正确的行为 - 当您添加一个新行的数据源,它只有一次发射

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.

不过,我也许应该提到(即使这不是你原来的问题),如果你使用的ASPX此事件处理的输出格式,比这里等效实际上是 CellFormatting 事件 - 这个事件被称为每当细胞需要显示它的价值

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.

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

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