TreeView nodes with indexes in C #

0

I need to know if it is possible to establish some kind of index / key to those nodes, the problem arises because I need to be able to create more accounts and if I have two accounts with the same name I need to know their exact location (the accounts that I have parents and daughters).

So if anyone has any idea or suggestion, welcome it.

    
asked by kenneth Steve Aguilar 18.09.2018 в 23:16
source

1 answer

0

You can use the property .Tag that has the TreeNode object. My recommendation would be that you use unique integers as identifiers, but seeing your TreeView I imagine that they come from different tables so it may be convenient to use pipe lines (|) to separate the Identifiers and then resume them with a split in this way:

  TreeNode tnActivo = new TreeNode();
        tnActivo.Text = "ACTIVO";
        tnActivo.Tag = "1";


        TreeNode tnActivoCorriente = new TreeNode();
        tnActivoCorriente.Text = "ACTIVO CORRIENTE";
        tnActivoCorriente.Tag = "1|1";

        TreeNode tnCaja = new TreeNode();
        tnCaja.Text = "CAJA";
        tnCaja.Tag = "1|1|1";

        TreeNode tnBancos = new TreeNode();
        tnBancos.Text = "BANCOS";
        tnBancos.Tag = "1|1|2";

        tnActivoCorriente.Nodes.Add(tnCaja);
        tnActivoCorriente.Nodes.Add(tnBancos);



        TreeNode tnActivoNoCorriente = new TreeNode();
        tnActivoNoCorriente.Text = "ACTIVO NO CORRIENTE";
        tnActivoNoCorriente.Tag = "1|2";


        tnActivo.Nodes.Add(tnActivoNoCorriente);
        tnActivo.Nodes.Add(tnActivoCorriente);

And to recover them you can use

        string[] identificador = tnBancos.Tag.ToString().Split('|');


        //DONDE identificador[0] = 1
        //DONDE identificador[1] = 1
        //DONDE identificador[2] = 2
    
answered by 28.09.2018 / 04:32
source