|
Is there a reason why when accessing the TreeNode.Text property is slows down the redraw of a treeview and it doesn't even take in consideration the BeginUpdate/EndUpdate of the TreeView???
In this example if you comment out the "NewNode.Text" line the
BeginUpdate/EndUpdate will work fine
TreeNode NewNode;
treeView.BeginUpdate();
for( int i = 0; i < 1000; i++ )
{
NewNode = treeView.Nodes.Add( "Node: " + i.ToString() );
NewNode.Text = "Node: " + i.ToString();
Application.DoEvents();
}
treeView.EndUpdate();
And in this example if you comment ou the "NewNode.Text" line the tree view will repaint alot faster.
TreeNode NewNode;
for( int i = 0; i < 1000; i++ )
{
NewNode = treeView.Nodes.Add( "Node: " + i.ToString() );
NewNode.Text = "Node: " + i.ToString();
Application.DoEvents();
}
|
|
|
|
|
Serge R wrote:
Is there a reason why when accessing the TreeNode.Text property is slows down the redraw of a treeview and it doesn't even take in consideration the BeginUpdate/EndUpdate of the TreeView???
In this example if you comment out the "NewNode.Text" line the
BeginUpdate/EndUpdate will work fine
I'm not sure what you are trying to do; the point of BeginUpdate/EndUpdate is to not-redraw the treeview while populating nodes making it faster because you won't redraw after each addition/removal. When you put in the Application.DoEvents() and by setting the text value you are telling it to redraw.
Nearest I can tell that is the culprit.
James
Simplicity Rules!
|
|
|
|
|
James T. Johnson wrote:
I'm not sure what you are trying to do
If it takes 5 min to load the tree I want to be able to move the window around without using a thread so I use Application.DoEvents()...
The best example is that I'm trying to do something like this product for myself: www.jamsoft.net/treesize.html
|
|
|
|
|
Comparing the source from MFC and the source for TreeNode (.NET), they do almost the exact same thing... BUT! The .NET TreeNode does a scrollbar update if the TreeView is scrollable.
Try setting Scrollable to false, when you call BeginUpdate; and to true when you call EndUpdate.
James
Simplicity Rules!
|
|
|
|
|
A couple of suggestions:
1) If you want to do a file system like thing, it usually works much better if you populate the tree on demand. I did something like for my book; if you find "A programmer's Introduction to C#" on the Apress website, you can download the source code.
2) It's a lot easier, and usually much more efficient to derive your own class from TreeNode and use that rather than using the string operations. Each time you call Add, it has to create a new TreeNode object and put the string into it, where if you have your own object already, it can be added directly. I do that in my code as well.
|
|
|
|
|
Thanks,
I'll probably have to go more fore the second suggestion because for the type of project I want to do, on demand is not a solution, I don't think I can do it another way, if you would know let me know please.
I want to display the size of the folder with the name of the folder to get the size a folder you need the size of each folder inside the folder so on and so on it's a recursive thing... so why not populate the tree in the mean time but we still want the user to have control of the application, move it, size it, minimize it, stop it, browse the folders that were loaded up to now, etc.
The main idea is:
LoadFolder( foldername )
{
int totalsize
add node
totalsize += size of files in foldername
for each sub folders in foldername
{
totalsize += LoadFolder( subfolder )
update new node text with totalsize
need to process messages here
}
return totalsize
}
then you just need to call LoadFolder( "c:\" ) on you button once If you look at this software it does exactly what I want to do...
www.jamsoft.net/treesize.html
|
|
|
|
|
I don't think I was very clear here. There are really two tasks:
1) Scanning the filesystem to figure out the size of each dir (which my app does).
2) Showing that information in the treeview.
The app requires #1, but it doesn't require putting all that information into the treeview at once. This can take quite a bit of time to do.
|
|
|
|
|
Is there a reason that the set of the TreeNode.Text property triggers the entire control to redraw/erase.
The SetItemText in MFC of the CTreeView does not trigger the entire control redraw/erase so there must be something extra in the set of the TreeNode.Text that make the control do that.
|
|
|
|
|
I don't know the answer to that, and it does seem to be a bug to me.
|
|
|
|
|
I'm not sure that I am correct, but I think you are actually resetting the what is shown on the screen with your line of:
NewNode.Text = "Node: " + i.ToString();
Thus it is having to rewrite over the same information. If you don't make the call to Application.DoEvents(); I think you will see that your screen does not flutter. Is there a reason that you are trying to process all the messages in the message queue here? Something like this should work fine.
TreeNode NewNode;
for( int i = 0; i < 1000; i++ )
{
NewNode = treeView.Nodes.Add( "Node: " + i.ToString() );
NewNode.Text = "Node: " + i.ToString();
}
HTH
Nick Parker
|
|
|
|
|
In MFC/Win32 when I change the text of a node it doesn't trigger the entire redraw of the the tree control I was just expecting the control to act the same way.
I'm mean I should be able to change the text of a node in a loop for more than one reason, progress, size increasing, etc.
If you look at the following link you'll see an application that uses that methode with processing messages or a thread but it his still updating the treeview wile giving control of the application to the user.
www.jamsoft.net/treesize.html
This example is in MFC (sorry to post this is a c# forum) and it changes the text of a node after it was added and it does not cause the entire control to redaw.
HTREEITEM NewNode;
CString strText;
for( int i = 0; i < 1000; i++ )
{
strText.Format( "Node: %d", i );
NewNode = m_TreeView.InsertItem( strText );
m_TreeView.SetItemText( NewNode, strText );
ProcessMessages();
}
|
|
|
|
|
Found the problem
As I speculated it is the Scrollable property that is causing the problem
TreeNode NewNode;
treeView.Scrollable = false;
treeView.BeginUpdate();
for( int i = 0; i < 1000; i++ )
{
NewNode = treeView.Nodes.Add( "Node: " + i.ToString() );
NewNode.Text = "Node: " + i.ToString();
Application.DoEvents();
}
treeView.Scrollable = true;
treeView.EndUpdate(); Regards,
James
Simplicity Rules!
|
|
|
|
|
Hello All,
I'm getting a value from a registry key that is of type REG_MULTI_SZ and I can't display it on the screen. Consider the following:
Console.WriteLine(_remoteRegKey.GetValue("Foobar").ToString());
This is the output I'm getting:
System.String[]
Can anyone enlighten me as to how I can get the value of the key ? Thanks in advance...
-Koby
|
|
|
|
|
It passes back an array of strings. Try, iterating it and displaying them individually...
|
|
|
|
|
Not sure that this will work, but something like this might.
for(int i = 0; i < _remoteRegKey.GetValue("Foobar").Count; i++)
{
Console.WriteLine(_remoteRegKey.GetValue("Foobar")[i].ToString());
}
Someone please correct me if I am wrong. James, I know you are lurking out there.
Nick Parker
|
|
|
|
|
I think you'll need to use this code since GetValue() returns an object;
string [] values = (string []) _remoteRegKey.GetValue("Foobar");
for(int i = 0; i < values.Length; i++)
{
Console.WriteLine(values[i]);
} James
Simplicity Rules!
|
|
|
|
|
Thanks James, I had been up for countless hours last night due to those damn finals. That is all over now, so you don't have to worry about me posting incorrect information now. Sorry for any of those that I mislead.
Nick Parker
|
|
|
|
|
I would like to make winform has the same behavier as Microsoft windows does, when user press Ctrl+C, it will copy the selection into a clipboard, and can use Ctrl+V to paste it to somewhere. Anyone knows how to achieve it?
thanks
chris#
|
|
|
|
|
Nish has written an article on Code Project that should show you how to implement the Clipboard class in your application. Here is the link in a new window. Clipboard handling with .NET
HTH
Nick Parker
|
|
|
|
|
Great! It helps a lot! However, I still have a question in mind: how about copy an object array, and paste it to somewhere? I have a ListView control in a form, contains several objects. I want to be able to copy multiple of them, can I do it? And if their type is not listed in dataFormats list, how can I retrieve them? Thanks again!
Chris#
|
|
|
|
|
I'm finding that it would be very useful to have a class property that would accept multiple entries. For example, I want to have a property that keeps track of 5 toolbar buttons automatically for me. So, I want to create a property where I can automatically get/set the toolbar collection via the IDE.
The following code 'almost' works. The property appears, I can click on the "..." button and the Collection Editor appears, but it doesn't save anything. The word "(Collection)" doesn't appear in the property.
Are there any examples out there that show how to do this?
[Category( "Controls" )]
[Description( "Add the list of ToolBarButtons that keep track of the modes" )]
public ToolBarButton[] ToolBar_ButtonModes
{
set{ m_ToolBar_ButtonModes = value; }
get{ return m_ToolBar_ButtonModes; }
}
private ToolBarButton[] m_ToolBar_ButtonModes = null;
-- Thanks!!
|
|
|
|
|
Just a hunch, but usually if you want to tell the IDE something about your properties, you need to use Attributes. Maybe try the Designer attribute, and pass it the standard ToolbarButton[] designer (if such a thing exists). Or maybe there is a CollectionType attribute.
Just guessing
--
David Wengier
Sonork ID: 100.14177 - Ch00k
|
|
|
|
|
I know that Code Project has a *utility* for transforming code for articles into the correct color format. Has anyone seen/written a class to do this for the new .NET Framework, if not I am seriously considering this as a new project in C# (after the screensaver that is )?
Nick Parker
|
|
|
|
|
I want to create something similar to the C# Form Designer include in the C# IDE but not too advanced, I just want to know how can I lock a Form in my Main Application Window, anybody know how to make something like this ?
thanks.
BTW, is it possible to create a DLL with the other dll I need to create an application like System.DLL, System.Windows.Form.DLL all those DLL include in one So after I can only compile my program using this DLL ??? if yes how can I do this ?
Thanks Again
|
|
|
|
|
BLaZiNiX wrote:
I want to create something similar to the C# Form Designer include in the C# IDE but not too advanced, I just want to know how can I lock a Form in my Main Application Window, anybody know how to make something like this ?
From what I can tell the VS.NET forms designer actually loads the form up into a temporary app domain and displays it in the window. To display a Form inside another form use this bit of code.
Form childForm = GetFormToDisplay();
childForm.TopLevel = false;
childForm.Location = GetLocation();
this.Controls.Add(childForm); You'll also have to hook several messages using Application.AddMessageFilter so that the child form can't be moved around (NCHITTEST plus some WM_SYSCOMMAND).
I have another message here that explains how to use Application.AddMessageFilter
James
Simplicity Rules!
|
|
|
|