De hier getoonde instellingen tonen hoe je een kolom (actions.contact) toevoegt 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 Tree bevat.
Bij het toevoegen van elke node in de Tree, wordt het event AddingNode opgeroepen in de ActionsTreeControl. Het event args laat ons het volgende zien:
- e.Node : de node die net werd toegevoegd.
- e.Node.Dr : de DataRow gekoppeld aan deze node.
- e.NodeType : het type Parent of Child
using System;
using System.Collections.Generic;
using System.Text;
using System.Windows.Forms;
using System.Drawing;
using MercatorUi;
using MercatorApi;
using System.Linq;
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") // query voor het niveau "parent"
{
stringToModify = stringToModify.Replace("actions.users,", "actions.users,actions.contact,");
}
else if (id == "SIG_ACTIONSTREE_CHILDS_CLI") // query voor het niveau "child"
{
stringToModify = stringToModify.Replace("actions.users,", "actions.users,actions.contact,");
}
return stringToModify;
}
public void FormLoadCustomize(Form form)
{
MercatorUi.Forms.Sig.SigForm sigForm = (MercatorUi.Forms.Sig.SigForm)form;
List<Control> l = sigForm.FindMovableControlsByType(typeof(MercatorUi.Forms.Sig.SigObjects.ActionsTree));
if (l.Any())
{
MercatorUi.Forms.Sig.SigObjects.ActionsTree actionTree = (MercatorUi.Forms.Sig.SigObjects.ActionsTree)l[0];
actionTree.ActionsTreeControl.AddingNode += ActionsTreeControl_AddingNode;
}
}
public void FormClosedCustomize(Form form)
{
MercatorUi.Forms.Sig.SigForm sigForm = (MercatorUi.Forms.Sig.SigForm)form;
List<Control> l = sigForm.FindMovableControlsByType(typeof(MercatorUi.Forms.Sig.SigObjects.ActionsTree));
if (l.Any())
{
MercatorUi.Forms.Sig.SigObjects.ActionsTree actionTree = (MercatorUi.Forms.Sig.SigObjects.ActionsTree)l[0];
actionTree.ActionsTreeControl.AddingNode -= 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();
}
}
}
Zie ook: Een kolom toevoegen in het ActionTree object van een verkoop of een aankoop