How can I create a reusable 3 states treeview

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi,

I am a new guy in C#. (I am a c++ developer long time already.)

I want to write a resuable 3 states treeview(check, uncheck,semicheck). I
want to handle Click event and BeforeExpand event in my resuable treeview ,
and I want to handle these events as the last event handler in the treeview,
and let user use it just like normal treeview in his form (to be able call
the functions, properties of treeview and to handle event of treeview.).

I don't know what kind of techincal I must use -- write my own class which
inherits from TreeVeiw, write a custom control or .... What is the major
different between these technologies.

Best Regards,
Michael zhang
 
You may be able to get the behavior you want by either using the TreeView
directly, or perhaps better, by inheriting from it. See the documentation on
the TreeView.Checkboxes property. It explains how you can get different
images to show in place of the standard checkboxes. You can probably wrap up
the logic you need to accomplish this in your own derived TreeView.

If you create your own custom control you'll have a lot more work to do.
You'll be reinventing a TreeView from nothing. I don't recommend going that
route unless you find serious obstacles inheriting from the existing
TreeView control.
 
Hi,

I am a new guy in C#. (I am a c++ developer long time already.)

I want to write a resuable 3 states treeview(check, uncheck,semicheck). I
want to handle Click event and BeforeExpand event in my resuable treeview ,
and I want to handle these events as the last event handler in the treeview,
and let user use it just like normal treeview in his form (to be able call
the functions, properties of treeview and to handle event of treeview.).

I don't know what kind of techincal I must use -- write my own class which
inherits from TreeVeiw, write a custom control or .... What is the major
different between these technologies.

Best Regards,
Michael zhang

Dear Michael,

If you need common handlers for the BeforeExpand handlers creating a
class that inherits the TreeView is an option. I can't check it right
now but i'm almost sure that there are protected methods to override
such as OnBeforeExpand..

Not sure it will answers your purposes but it's nice to know, In c#
3.0 you will be able to use extension methods, to extend existing
methods of classes (even if you don't have the source):
http://blogs.msdn.com/abhinaba/archive/2005/09/15/467926.aspx
http://www.interact-sw.co.uk/iangblog/2005/09/26/extensionmethods

By Custom control, you mean what, like in C++? By inheriting the
TreeView, you have a custom control already, since the treeview class
is a Control. :)

You can use wrapping techniques but I don't think it suits your needs.
About the states of the node, again I can't check it right now but
there should be state images in the TreeNode class.

I will be able to check it later on, please let me know if you managed
to find it.

Hope this helps,
Moty.
 
Hi,

I am a new guy in C#. (I am a c++ developer long time already.)

I want to write a resuable 3 states treeview(check, uncheck,semicheck). I
want to handle Click event and BeforeExpand event in my resuable treeview ,
and I want to handle these events as the last event handler in the treeview,
and let user use it just like normal treeview in his form (to be able call
the functions, properties of treeview and to handle event of treeview.).

I don't know what kind of techincal I must use -- write my own class which
inherits from TreeVeiw, write a custom control or .... What is the major
different between these technologies.

Best Regards,
Michael zhang

Dear Michael,

I would suggest inheriting the TreeView class and overriding the event
method (OnBeforeExpand). I can't check this right now, but I am almost
positive it's feasible.
It's already a Custom Control when inheriting the TreeView that is a
Control itself.

In C# 3.0 you will be able to extend the methods of the TreeView class
using extension methods:
http://blogs.msdn.com/abhinaba/archive/2005/09/15/467926.aspx
http://blogs.msdn.com/abhinaba/archive/2005/09/15/467926.aspx

I can't check things right now but I think there are State Image
property of the TreeNode class.

Feel free to ask further questions about the issue.

Cheers,
Moty
 
Hi,

Thanks a lot.

BTW, In C# 3.0, I am even unable to find a way to display image for tree
node. Do you know it?

Yours,
Michael zhang
 
Hi,

Actually, I mean I cannot find ImageList and StateImageList in
System.Windows.Controls.TreeView.

So I don't know how to display a state Image, an image with the text for the
TreeViewItem.

Michael zhang
 
Back
Top