how to set integer in treenode tag

Posted on 2008-11-10
Last Modified: 2013-12-17
I need to save a counter for each tree node and I think the best place to store is in the node.tag
my question is how could I make the tag store integer number so i can increment it each time

p.s i am using tree view in c#

thanks in  advance for your help


Question by:suzan_
    LVL 18

    Accepted Solution

    TreeNode.Tag actually accepts object data type, which means you can assign anything, including integer. The only thing to remember is that, don't assign it through the visual studio designer, because it will treat data as string.

    To assign:
    node.Tag = 1;

    To read data:
    int tagValue = (int) node.Tag;

    Author Comment

    thanks a lot philipjonathan
    its really help

    Featured Post

    Find Ransomware Secrets With All-Source Analysis

    Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

    Join & Write a Comment

    More often than not, we developers are confronted with a need: a need to make some kind of magic happen via code. Whether it is for a client, for the boss, or for our own personal projects, the need must be satisfied. Most of the time, the Framework…
    A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
    It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
    In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

    733 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    19 Experts available now in Live!

    Get 1:1 Help Now