am i using the tag property the right way? please take a look ...

G

garyusenet

I could do with something similiar, can you tell me if you think this
would work for me, and if there's any advantage in working with
controls
this way than how I currently am.

At the moment i'm using the treenodes and each treenode needs a unique
entry into my rich text box. After sitting at home with MSDN i've
managed to get this functionality by storing a RTF string in the tag
property of the treenode. On every 'before update' of the treeview I
save the current RTF string from the rich textbox to the tag property
of the selected node. On every 'after update' I pull in the RTF from
the selected tag property into the rich text box.


Would it be better for me to have a new class with a richtext property
or something? or is the way i'm doing it perfectly OK?


Am i right in thinking a new class would mean that i'd create new
objects which would have all the functionality of the treeview control,
all treeview properties etc... but also extra properties / methods that
I specify? If this is the case, would there be a property better suited
to storing richtext that I could create which is different to the
already provided tag property?

My treenode collection will have about 40 nodes, and each node will
have its own richtext associated with it eventually - the richtext is
typically 1-3 pages worth per node.

Should I be storing this info in a database instead of the tag
property? At the moment i'm serialising the treeview and saving to a
file, which conveniently captures the rich text entries too as i'm
storing them in the tag property.

Finally a previous post I was reading about creating your own objects
mentioned common
interface and polymorphism could someone explain this please, i've
never tried creating my own class from an already existing class
before.


Many Thanks.


Gary.
 
K

Kevin Spencer

Hi Gary,
Would it be better for me to have a new class with a richtext property
or something? or is the way i'm doing it perfectly OK?

It all depends. There are a couple of possible reasons for making a new
class. For example, reusability. If you anticipate reusing this class in a
similar way in the future, it might make sense to create a derived class
which includes the functionality you're specifying, and is extensible for
re-purposing. If, on the other hand, you don't, creating a new class might
be a waste of time. And keep in mind that designing a new class will be
time-consuming, if you design it right.
Am i right in thinking a new class would mean that i'd create new
objects which would have all the functionality of the treeview control,
all treeview properties etc... but also extra properties / methods that
I specify?

Pretty much, yes.
If this is the case, would there be a property better suited
to storing richtext that I could create which is different to the
already provided tag property?

The tag property, while very useful, is of type object. You would be able to
be more specific about what type you attach to a new property, and of
course, the tag property would still be availble for other possible uses.
Should I be storing this info in a database instead of the tag
property? At the moment i'm serialising the treeview and saving to a
file, which conveniently captures the rich text entries too as i'm
storing them in the tag property.

The word "database" has always been a stumbling block for a lot of people.
What is a database? In essence, it is a permanent storage mechanism for
data. That is, of course, what your file is. So, what you're really asking
is, should you substitute one sort of database for another?

The answer, again, depends upon several factors. Most commercial database
products store data in a tabular fashion. But from what you're describing,
your data is hierarchical in nature. While hierarchical data can be stored
in tablular fashion, it is somewhat complex to do so. On the other hand, if
you expect this to be a multi-user application, with many clients accessing
the same data, and possibly at the same time, a database server might suit
you better than your current solution.
Finally a previous post I was reading about creating your own objects
mentioned common
interface and polymorphism could someone explain this please, i've
never tried creating my own class from an already existing class
before.

This is a real can of worms, and it would take more time than I have to
explain it fully. Abstractly speaking, an interface is a mechanism for
access. In software, there are many kinds of interfaces. The user interface
is the most widely known; it provides a human-friendly mechanism for
accessing the functionality contained in a piece of software. A programming
interface is a mechanism that enables software to access the functionality
contained in a piece of software. The only real difference is what the
client-side of the interface "looks like" - how it works, that is.

In a programming interface, such as that exposed by a class, there are
publicly-available properties, methods, etc., for which the "signatures" are
known. That is, the type and number of parameters, the type of the return
value, etc. Taken even more abstractly, OOP provides interfaces that are not
classes at all, but simply definitions of the "signatures" of an interface.
While a class *has* its own interface, it may also *implement* an interface
that is not a class, but simply an interface. The purpose of such interfaces
is to gurantee a standard that is known to the client, or user. A client
doesn't necessarily have to know everything about a class to make use of it.
It may simply want to perform some common task with it. If it knows that the
class implements a certain interface, it can make method calls, use
properties, etc., without knowing anything at all about the class, other
than the fact that it implements the interface needed.

Polymorphism is a bit more difficult to define easily. The best and most
common examples are overloading and overriding. Overloading is when several
different methods (or functions) have the same name, but take different
parameters, and may yield entirely different results. For example:

String.IndexOf(string)
String.IndexOf(string, int)
String.IndexOf(string, int, int)

Overriding is the one that you may be thinking of here. That is when a
derived (inherited) class, which inherits a method or a property, does
something additional or different when that property or method is invoked.
For example, in a Windows Form application, you often override one of the
On-Event event methods in the base Form class. Usually, you begin by
executing the base class's method, and then perform some additional work,
such as handling a button click.

You may find the following article enlightening, for more information about
the 4 pillars of OOP:

http://codebetter.com/blogs/raymond.lewallen/articles/59908.aspx

--
HTH,

Kevin Spencer
Microsoft MVP
Professional Numbskull

Show me your certification without works,
and I'll show my certification
*by* my works.
 
G

garyusenet

Thankyou for your time and considerable efforts. Your post has been
very enlightening and given me a lot to think about. Day by day i'm
moving closer to a more fuller understanding of Visual C# and .net (I
know i have a very long way to go.) - Thank's again you have helped
immeasurably!

Gary.
 

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

Top