Hello People im filling datagrid when on forms load event this way:
private void Inventory_Load(object sender, EventArgs e)
{
AcidDBDataContext db = new AcidDBDataContext();
BindingSource bs = new BindingSource();
bs.DataSource = db.GetProducts.ToList();
dgvInventory.DataSource = bs;
ProductBindingNavigator.BindingSource = bs;
ShowtoolStripButton2.Visible = false;
foreach (DataGridViewColumn c in dgvInventory.Columns)
{
c.DefaultCellStyle.Font = new Font("Arial", 12.0F, GraphicsUnit.Pixel);
}
}
its working fine but there is one problem i needs few second and my form is freezing. How i can do while my datagrid is filling show loading animation and when grid will be filled hide animation
Im using C# winForms.
THanks a lot
You could look into BackgroundWorkerThreads.
http://www.albahari.com/threading/part3.aspx
I used them quite a bit while retrieving data. I would display a waiting bar, call the DoWork event where data is retrieved into a dataset (for us, this usually took longer than attaching said data to the grid), then in the RunWorkerCompleted event I attached the data to the grid and hid the waiting bar. The app still froze for a few seconds, but not nearly as long.
Here’s some sample code. Basically, lock fields that could cause
RefreshInventoryto be called again (but since you’re loading at startup maybe that doesn’t apply to you). Then retrieve the data in the thread and attach it when the thread is done.