Nevron Forum

Trying to add button to an NTreeListNode subitem

https://www.nevron.com/Forum/Topic4120.aspx

By lars knox - Friday, September 3, 2010

Hi,

I'm trying to add a command button (or NButton or anything else that can act like a button and display an image) to a subitem of an NTreeListNode.

I've been searching the forum and perusing the documentation but haven't been able to find any answers yet.

Do you have a snippet of code that could show how this is done please? Thanks!

 

By Nevron Support - Friday, September 3, 2010

Hi Lars,

You can use NTreeListNodeImageSubItem to display an image to a subitem.

To handle the click event you should attach to ItemNotify event as in the example code below:

NTreeListColumn column = new NTreeListColumn();
nTreeList1.Columns.Add(column);

NTreeListNode node = new NTreeListNode();
NTreeListNodeImageSubItem imageSubItem = new NTreeListNodeImageSubItem();

imageSubItem.Image = myImage
;
imageSubItem.Column = column;
node.SubItems.Add(imageSubItem);
nTreeList1.Nodes.Add(node);

nTreeList1.ItemNotify +=
new NLightUIItemNotifyEventHandler(nTreeList1_ItemNotify);

...

void nTreeList1_ItemNotify(object sender, NLightUIItemNotifyData data)
{
    if (data.NotifyCode == NTreeList.ItemLabelClickNotifyCode)
    {
        NTreeListNode currentNode = (NTreeListNode)data.Sender;
        NTreeListNodeImageSubItem clickedItem = (NTreeListNodeImageSubItem)currentNode.ResolveSubItem(nTreeList1.Columns[0]);
    }
}

The only drawback here is that you can't determine on which sub item exactly is clicked if you do not know the item's column.