知道DataBinding何时完成

时间:2012-04-06 04:24:52

标签: c# winforms binding datagridview

我在我的应用中使用System.ComponentModel.BindingList作为DataGridView.DataSource。该列表非常大,需要几秒钟才能在DataGridView上绘制。所以,我需要知道数据绑定(包含绘画)过程何时完成一些事情。我尝试了DataBindingComplete事件,但是在将值设置为DataSource属性后立即发生。

提前致谢。


更新:

1. :生成绑定列表 [从数据库中获取数据] ►~1秒

2. 将其设置为DataSource [绑定] ►~1秒({{1}现在就被提出来了。)

3。绘画 [显示DataBindingComplete ] 中的数据►~5秒

1 个答案:

答案 0 :(得分:5)

这就像描述一样简单!

bool bindingCompleted = false;

void Form1_Load(object sender, EventArgs e)
{
    dataGridView1.DataSource = bindingList1;
}

void dataGridView1_DataBindingComplete(object sender, DataGridViewBindingCompleteEventArgs e)
{
    bindingCompleted = true;
}

void dataGridView1_Paint(object sender, PaintEventArgs e)
{
    if (bindingCompleted)
    {
       bindingCompleted = false;

       // do some stuff.. 
    }
}