Datagrid display records too slow

Q

qilinw

In a winform I want to display database records using datagrid, with
dataset for a couple of thousands records it seems very slow. I have
read an article in group microsoft.public.dotnet.languages.vb. It uses
datareader to solve this problem, it's a good idea. I have translated
it in c# and want to run this in a separate thread, but it does not
work, i have a blank datagrid.

Anyone can help me? Thanks a lot.

My source code is following:

static private System.Threading.Thread m_pThread = null;

public void FillDataGrid()
{
DataTable dtList = dbman.GetOrderListSchema();
dataGrid_orderlist.DataSource = dtList;
SqlDataReader reader = dbman.GetOrderListPro();

while( reader.Read() )
{
DataRow dr = dtList.NewRow();
object[] tmp = new object[dtList.Columns.Count-1];
reader.GetValues(tmp);
dr.ItemArray = tmp;
dtList.Rows.Add(dr);
dataGrid_orderlist.Refresh();
}

reader.Close();
}

private void FormSearch_Load(object sender, System.EventArgs e)
{
m_pThread = new System.Threading.Thread(new
System.Threading.ThreadStart(FillDataGrid));
m_pThread.Name = "FillDataGrid";
m_pThread.IsBackground = true;
m_pThread.Start();
}
 
G

Guest

Is the user legitimately going to need to see all couple of thousand records?
Why not put some filter controls on the form and let the user select what
they need, and use these as part of the WHERE SQL clause.
Peter
 
J

Jon Skeet [C# MVP]

In a winform I want to display database records using datagrid, with
dataset for a couple of thousands records it seems very slow. I have
read an article in group microsoft.public.dotnet.languages.vb. It uses
datareader to solve this problem, it's a good idea.

It's only a good idea if you've *proven* that it improves the
performance significantly. You should test each of them individually
(with nothing else happening, so in a console app).
I have translated
it in c# and want to run this in a separate thread, but it does not
work, i have a blank datagrid.

Anyone can help me? Thanks a lot.

Well for one thing, if your DataTable is bound in the UI you mustn't
change it from another thread, otherwise you'll trigger a refresh in
the wrong thread. You need to either create a new DataTable, fill that,
*then* bind to it, or pass the data back to the UI thread and fill the
DataTable up there.
 
Q

qilinw

Hi, Peter,

as default if user do not give any condition all records should be
displayed. That is what I must do, I have no choice. :-(
Is the user legitimately going to need to see all couple of thousand records?
Why not put some filter controls on the form and let the user select what
they need, and use these as part of the WHERE SQL clause.
Peter

--
Co-founder, Eggheadcafe.com developer portal:
http://www.eggheadcafe.com
UnBlog:
http://petesbloggerama.blogspot.com




In a winform I want to display database records using datagrid, with
dataset for a couple of thousands records it seems very slow. I have
read an article in group microsoft.public.dotnet.languages.vb. It uses
datareader to solve this problem, it's a good idea. I have translated
it in c# and want to run this in a separate thread, but it does not
work, i have a blank datagrid.

Anyone can help me? Thanks a lot.

My source code is following:

static private System.Threading.Thread m_pThread = null;

public void FillDataGrid()
{
DataTable dtList = dbman.GetOrderListSchema();
dataGrid_orderlist.DataSource = dtList;
SqlDataReader reader = dbman.GetOrderListPro();

while( reader.Read() )
{
DataRow dr = dtList.NewRow();
object[] tmp = new object[dtList.Columns.Count-1];
reader.GetValues(tmp);
dr.ItemArray = tmp;
dtList.Rows.Add(dr);
dataGrid_orderlist.Refresh();
}

reader.Close();
}

private void FormSearch_Load(object sender, System.EventArgs e)
{
m_pThread = new System.Threading.Thread(new
System.Threading.ThreadStart(FillDataGrid));
m_pThread.Name = "FillDataGrid";
m_pThread.IsBackground = true;
m_pThread.Start();
}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Top