all groups > dotnet compact framework > march 2008 >
You're in the

dotnet compact framework

group:

Treeview loading with BeginUpdate&EndUpdate


Treeview loading with BeginUpdate&EndUpdate Freesc
3/25/2008 5:10:45 AM
dotnet compact framework:
Hi there~

As is known to all, the Treeview::BeginUpdate/EndUpdate method is used
to update or reload the treeview without redrawing the treenode one by
one,and it can save some performance for us.But here i'm writing an
example that,however,doesn's make any difference with or without these
two method.Here's my code:

public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}

void TestTreeViewLoad(bool async)
{
int start = Environment.TickCount;
int end = 0;
//
// Use the BeginUpdate/EndUpdate asynchronized or not?
//
//if (async)
treeView1.BeginUpdate();

treeView1.Nodes.Clear();
end = Environment.TickCount;
Debug.WriteLine("Treeview Clear time (ms): " + (end -
start));
//
// Root node
//
TreeNode tn = new TreeNode(@"\");
treeView1.Nodes.Add(tn);
DirectoryInfo rootDir = new DirectoryInfo(@"\");
end = Environment.TickCount;
Debug.WriteLine("Treeview Addtoot time (ms): " + (end -
start));
//
// Update the TreeView control with the directory tree
//
UpdateTreeView(tn, rootDir);
treeView1.Nodes[0].Expand();
end = Environment.TickCount;
Debug.WriteLine("Treeview update time (ms): " + (end -
start));

//if (async)
// treeView1.EndUpdate();
treeView1.EndUpdate();
end = Environment.TickCount;

Debug.WriteLine("Treeview load time (ms): " + (end -
start));
}

//
// Recursively update tree view
//
private void UpdateTreeView(TreeNode tn, DirectoryInfo dir)
{
//
// Display folder names; Recursively call the method
//
foreach (DirectoryInfo di in dir.GetDirectories())
{
TreeNode tn2 = new TreeNode(di.Name);
tn.Nodes.Add(tn2);
UpdateTreeView(tn2, di);
}

//
// Display file names
//
foreach (FileInfo fi in dir.GetFiles())
{
TreeNode tn3 = new TreeNode(fi.Name);
tn.Nodes.Add(tn3);
}
}
private void menuItem1_Click(object sender, EventArgs e)
{
TestTreeViewLoad(true);
}
}

*********Output with aysnc update**********
Treeview Addtoot time (ms): 687
Treeview update time (ms): 5177
Treeview load time (ms): 5260

*********Output without aysnc update**********
Treeview Addtoot time (ms): 697
Treeview update time (ms): 5197
Treeview load time (ms): 5280

Obviously,the update operation takes a long time,and it seems that
BeginUpdate&EndUpdate doesn't work...

Any suggustion about that?

Thanks in advance

Regards
Re: Treeview loading with BeginUpdate&EndUpdate Freesc
3/25/2008 5:13:42 AM
[quoted text, click to view]

In addition,
i'm using IBM thinkpad X60+VS2008+.NET CF3.5+WM6 Standard Emulator for
developing and test

:-)

Re: Treeview loading with BeginUpdate&EndUpdate Jin Chang
3/25/2008 9:59:24 AM
[quoted text, click to view]

I think you're reading into BeginUpdate and EndUpdate a bit too much.
Your example seems to indicate the that majority of your run time is
due to retrieving the directory information. The advantages of
BeginUpdate and EndUpdate functions will be more obvious if the
information being loaded is, for example, from a memory variable like
an array. These function simply prevent the control from updating as
the items are added or modified, thus eliminating the unnecessary
visual processing. Depending on the amount of data involved, this may
Re: Treeview loading with BeginUpdate&EndUpdate Freesc
3/25/2008 7:14:16 PM
[quoted text, click to view]

Jin,
Thanks for your reply.
I think i got some twisted about BeginUpdate/EndUpdate, and now i'm
clear :)
the majority of the performance is due to retrieving the directory
information,not the refreshing of the treeview

thx & regards
Freesc
AddThis Social Bookmark Button