Knowing when DataBinding is completed
binding, c#, datagridview, winforms
Solution
That was as easy as described!
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..
}
}
Problem
I've used the `System.ComponentModel.BindingList` as the `DataGridView.DataSource` in my app. The list is quite large and takes some seconds to be painted on the `DataGridView`. So, I need to know when data-binding (included painting) procedure finishes to do some stuff. I tried `DataBindingComplete` event, but it occurs right after setting a value to the `DataSource` property. Thanks in advance. UPDATE: 1. Generating binding-list [ Getting data from Database ] ► ~1 sec 2. Setting it to `DataSource` [ Binding ] ► ~1 sec (The `DataBindingComplete` is raised right now.) 3. Painting [ Displaying data in the `DataGridView` ] ► ~5 sec