Een kolom toevoegen in het ActionTree object van een signalitiek.

0000002620     -      29-03-2016

De hier getoonde instellingen tonen hoe je een kolom toevoegd in het ActionTree object van het informatiebestand "Klanten". Het proces om een kolom toe te voegen aan een boomstructuur is iets anders dan een kolom toe te voegen aan een datagridview.

In eerste instantie, zal de customizer SigCli de interface MercatorUi.ICustomizers.IStringUpdater, implementeren, deze zal de 2 SQL-query's aanpassen:

  • De query om een lijst van parents op te halen. Deze wordt herkend door een id: SIG_ACTIONSTREE_PARENTS_CLI
  • De query om een lijst met childs op te halen, herkend door een id SIG_ACTIONSTREE_CHILDS_CLI

(In het ID, moet CLI vervangen worden door desbetreffend informatiebestand)

En tweede instantie, moet men het evenement AddingNode toevoegen, gedefinieerd in de klasse MercatorUi.Forms.Sig.SigClasses.ActionsTreeControl. Om de instantie van deze klasse te bereiken, gebruik je volgende boomstructuur: MercatorUi.Forms.Sig.SigObjects.ActionsTree gedefinieerd als object in de SigForm, bevat de MercatorUi.Forms.Sig.SigClasses.ActionsTreeControl, die zelf een control Treebevat.

Bij het toevoegen van elk knooppunt in de Tree, wordt het event AddingNode in de ActionsTreeControl verhoogd. Het event args laat ons het volgende zien:

  • e.Node : het knooppunt dat is toegevoegd.
  • e.Node.Dr : de DataRow geassocieerd met dit knooppunt.
  • e.NodeType : het type Parent of Kind
Zoom
using System;
using System.Collections.Generic;
using System.Text;
using System.Windows.Forms;
using System.Drawing;
using MercatorUi;
using MercatorApi;
using System.Data;


namespace SigCli
{
    public class Customizer : MercatorUi.ICustomizers.IFormLoadCustomizer, MercatorUi.ICustomizers.IFormClosedCustomizer,
                              MercatorUi.ICustomizers.IStringUpdater
    {
        string MercatorUi.ICustomizers.IStringUpdater.StringUpdate(string StringToModify)
        {
            string id = Api.StrExtract(StringToModify, "/*<ID>", "</ID>*/");
            if (id == "SIG_ACTIONSTREE_PARENTS_CLI") // vereist voor het niveau "parent"
            {
                StringToModify = StringToModify.Replace("actions.users,", "actions.users,actions.contact,");
            }
            else if (id == "SIG_ACTIONSTREE_CHILDS_CLI") // vereist voor het niveau "enfant"
            {
                StringToModify = StringToModify.Replace("actions.users,", "actions.users,actions.contact,");
            }
            return StringToModify;
        }

        public void FormLoadCustomize(Form WindowsForm)
        {
            MercatorUi.Forms.Sig.SigForm sigForm = (MercatorUi.Forms.Sig.SigForm)WindowsForm;

            List<Control> l = sigForm.FindMovableControlsByType(typeof(MercatorUi.Forms.Sig.SigObjects.ActionsTree));
            if (l.Count > 0)
            {
                MercatorUi.Forms.Sig.SigObjects.ActionsTree actionTree = (MercatorUi.Forms.Sig.SigObjects.ActionsTree)l[0];
                actionTree.ActionsTreeControl.AddingNode += new MercatorUi.Forms.Sig.SigClasses.ActionsTreeControl.AddingNodeEventHandler(ActionsTreeControl_AddingNode);
            }
        }

        public void FormClosedCustomize(Form WindowsForm)
        {
            MercatorUi.Forms.Sig.SigForm sigForm = (MercatorUi.Forms.Sig.SigForm)WindowsForm;

            List<Control> l = sigForm.FindMovableControlsByType(typeof(MercatorUi.Forms.Sig.SigObjects.ActionsTree));
            if (l.Count > 0)
            {
                MercatorUi.Forms.Sig.SigObjects.ActionsTree actionTree = (MercatorUi.Forms.Sig.SigObjects.ActionsTree)l[0];
                actionTree.ActionsTreeControl.AddingNode -= new MercatorUi.Forms.Sig.SigClasses.ActionsTreeControl.AddingNodeEventHandler(ActionsTreeControl_AddingNode);
            }
        }

        void ActionsTreeControl_AddingNode(object sender, MercatorUi.Forms.Sig.SigClasses.ActionsTreeControl.AddingNodeEventArgs e)
        {
            MercatorUi.Forms.Sig.SigClasses.ActionsTreeControl actionsTreeControl = (MercatorUi.Forms.Sig.SigClasses.ActionsTreeControl)sender;
            if (actionsTreeControl.Tree.Columns.Count == 7) // 7 = Aantal standaardkolommen -deze code wordt maar 1x uitgevoerd
            {
                DevComponents.AdvTree.ColumnHeader colContact = new DevComponents.AdvTree.ColumnHeader(_Divers.Iif_langue(Globals.Langue, "Contact", "Contactpersoon", "Contact"));
                colContact.SortingEnabled = false;
                colContact.Width.Absolute = 200;
                actionsTreeControl.Tree.Columns.Add(colContact);
            }
            _Divers.AddCellsToNode(e.Node, 1); // Als we een kolom toevoegen, moeten we een cel toevoegen aan elke node.
            e.Node.Cells[7].Text = e.Node.Dr["contact"].ToString();
            if (e.NodeType == MercatorUi.Forms.Sig.SigClasses.ActionsTreeControl.NodeEnum.Parent)
                e.Node.Cells[7].Text = "Parent=" + e.Node.Dr["contact"].ToString();
            else
                e.Node.Cells[7].Text = "Enfant=" + e.Node.Dr["contact"].ToString();
        }
    }
}