winform中的gridview rowdatabound事件? [英] gridview rowdatabound event in winforms?

查看:33
本文介绍了winform中的gridview 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 中处理此事件,但我找不到类似的事件.我的问题是允许我在 asp.net 中执行与 RowDataBound 相同的事件名称是什么?

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.

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

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