Click or drag to resize
CTInterfaceOnCustomListUpdate Event
Invoked for each Custom-type lookuplist at CUSTOMTOOLS start up and when 'Run' is clicked at Options for the Custom-type lookuplist in question. Allows full control over the lookuplist content.

Namespace: ATR.CT.CTInterface
Assembly: CTInterface (in CTInterface.dll)
Syntax
public event EventHandler<CTInterfaceCustomListUpdateArgs> OnCustomListUpdate

Value

Type: SystemEventHandlerCTInterfaceCustomListUpdateArgs
Examples
This sample shows how you can use CustomLookup class to easily control content of a Custom-type lookuplist.
C#
// @auto-reference {[CT_INSTALL_PATH]\\Interop.CTEngineLib.dll}
// @auto-reference {[CT_INSTALL_PATH]\\CTInterface.dll}

using System;
using System.Collections.Generic;
using System.Text;
using ATR.CT.CTInterface;
using CTEngineLib;

namespace ExportScripts
{

  /// <summary>
  /// Inherit the helper class or use it as a member.
  /// </summary>
  public class CustomLookupExample : ATR.CT.CTInterface.CustomLookup
  {

    private CTInterface moCTInterface;

    // LookupItem is a helper class for creating new value rows. 
    // It's a sub-class of ATR.CT.CTInterface.CustomLookup.
    private List<LookupItem> moLookupItems;

    /// <summary>
    /// Constructor. Attaches to the update-event.
    /// The event is fired on customtools startup and when "Run" is clicked for custom type lookuplist
    /// at lookuplist wizard. (Note that add-ins are not loaded when Admin Tool is used!)
    /// </summary>
    /// <param name="ctInterface"></param>
    public CustomLookupExample(CTInterface ctInterface)
    {
      moCTInterface = ctInterface;
      moCTInterface.OnCustomListUpdate += new EventHandler<CTInterface.CustomListUpdateArgs>(OnCustomListUpdate);
    }

    /// <summary>
    /// Event handler
    /// </summary>
    private void OnCustomListUpdate(object sender, CTInterface.CustomListUpdateArgs e)
    {

      ICTLookupList oList = e.LookupList; // Event is fired for this list

      // Use this add-in only for the list which name is "List1"
      if (String.Compare(oList.Name, "List1", true) != 0)
        return;

      // Initialize the object list.
      moLookupItems = new List<LookupItem>();

      // If this constructor is used. Value is set to "empty". This is because empty values are not allowed. 
      LookupItem item1 = new LookupItem();  // item1.Value == "empty"
      item1.Value = "Value1";
      moLookupItems.Add(item1); // Collect all the created items

      // This constructor sets also value.
      LookupItem item2 = new LookupItem("Value2"); 
      moLookupItems.Add(item2);

      // If we want to define keys (in case of key-value or hierarchial list)
      item1.SetKey(1, "Key1 for Value1"); // keys are between 1-15
      item2.SetKey(7, "Key7 for Value2");

      // Keys can also be defined in LookupItem's constructor. If used, the key-array's length must be 15.
      //LookupItem item3 = new LookupItem("Value3", new String[] { "k1", "k2", ... , "k15" });

      // In case of a hierarchial list...
      LookupItem childItem1 = new LookupItem("ChildValue1");
      item1.AddChild(childItem1);
      moLookupItems.Add(childItem1); // Remember to collect all created items

      // ..or..
      LookupItem childItem2 = new LookupItem("ChildValue2", item1);
      moLookupItems.Add(childItem2);

      // Lets add one child for item2 as well..
      moLookupItems.Add(new LookupItem("ChildValue3", item2));


      // Oh, wait! I want childItem2 to be sorted before childItem1 under item1
      childItem2.SortOrder = 1; // By default, SortOrder is 0. Negative is not alowed.
      childItem1.SortOrder = 2;


      // And now the magic 
      e.RetXml = CreateXMLString(moLookupItems); /* TADAA */



    }
  }
}
Availability

CUSTOMTOOLS 2013 SP4


See Also