De hier getoonde instellingen tonen hoe je een kolom (actions.contact) toevoegt in het ActionTree object van een bestek. 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 Billing 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: BILLING_ACTIONSTREE_PARENTS_DEVIS
- De query om een lijst met childs op te halen, herkend door een id BILLING_ACTIONSTREE_CHILDS_DEVIS
(In het ID, moet DEVIS vervangen worden door desbetreffende sequentie).
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 BillingForm, 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 MercatorExtensions;
using System.Linq;
namespace Billing
{
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 == "BILLING_ACTIONSTREE_PARENTS_DEVIS") // query voor het niveau "parent"
{
stringToModify = stringToModify.Replace("actions.users,", "actions.users,actions.contact,");
}
else if (id == "BILLING_ACTIONSTREE_CHILDS_DEVIS") // query voor het niveau "child"
{
stringToModify = stringToModify.Replace("actions.users,", "actions.users,actions.contact,");
}
return stringToModify;
}
public void FormLoadCustomize(Form form)
{
MercatorUi.Forms.Billing.BillingForm billingForm = (MercatorUi.Forms.Billing.BillingForm)form;
List<Control> l = billingForm.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.Billing.BillingForm billingForm = (MercatorUi.Forms.Billing.BillingForm)form;
List<Control> l = billingForm.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 == 8) // 8 = 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[8].Text = e.Node.Dr["contact"].ToString();
if (e.NodeType == MercatorUi.Forms.Sig.SigClasses.ActionsTreeControl.NodeEnum.Parent)
e.Node.Cells[8].Text = "Parent=" + e.Node.Dr["contact"].ToString();
else
e.Node.Cells[8].Text = "Enfant=" + e.Node.Dr["contact"].ToString();
}
}
}
Zie ook: Een kolom toevoegen in het ActionTree object van een informatiebestand