I'm having multiple gridview in my form and one of gridview rows is painted based on data.
But it looks weird when I load the form, it's like controls not having proper rendering on form.
Please look at this video for better understanding:
I'm having multiple gridview in my form and one of gridview rows is painted based on data.
But it looks weird when I load the form, it's like controls not having proper rendering on form.
Please look at this video for better understanding:
From the video what I could understand is it is taking time to Load,
If you have written the ADO.NET(to get data from DB) on Load Method, it will take a moment to fetch and display them.
I would advise you to use individual threads(for each Grid) to fetch data during the Load, to Optimize the performance.
I am not sure if this will solve your problem entirely but here are some tips/tricks :
! . If you are updating the Datagridview
source, try setting AutoSizeColumnsMode
to none before updating the datasource.This has been proven to work.
2 . There's a property called DoubleBuffer
.I am not gonna dig into the description of it but in easy words , it will help u to improve your performance significantly :)
static class ExtensionMethods
{
public void DoubleBuffered(DataGridView dgv, bool setting)
{
Type dgvType = dgv.GetType();
PropertyInfo pi = dgvType.GetProperty("DoubleBuffered", BindingFlags.Instance | BindingFlags.NonPublic);
pi.SetValue(dgv, setting, null);
}
}
ExtensionMethods.DoubleBuffered(mydgvw, True);
3 . Last but not the least, when displaying data in dgvw from a datasource, sometimes it is helpful to use collections like ObserveableCollection
or if possible,try to reduce the amount of displayed data through filtering.
4 . Using a DataReader
over a DataAdapter
is significantly faster.Create a class to manage your data,use a DataReader
instead of a DataAdapter
/DataTable
. E.g.
public class Employees
{
private int age;
public int Age
{
get { return age; }
set { age = value; }
}
private string name;
public string Name
{
get { return name; }
set { name = value; }
}
private int id;
public int Id
{
get { return id; }
set { id = value; }
}
}
///create an array
ArrayList myData = new ArrayList();
///Now,let ur datareader do the job for you .
while (reader.Read())
{
Employees emp = new Employees();
emp.Id = (int)reader[0];
emp.Name = reader[1].ToString();
emp.Age = (int)reader[2];
myData.Add(m);
}
dataGridView1.DataSource = myData;
4 . Another best bet is,if u use a Datareader
and follow the above code,make sure to run it in the background on the main form load, then on button clicks , just set the dataGridView.DataSource
to the array....
These are the basics but hope they'll help you :)