Nevron Forum

Selected Item in Treelist

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

By Ignacio Mendiguren - Friday, October 7, 2011

Hi,


I am new to Nevron components and am working with the treelist.
I wonder what is the way to get the selected item from the treelist?

Thanks,

IM
By Nevron Support - Friday, October 7, 2011

Hi Ignacio,

NTreeList control you can select the whole row which is represented by NTreeListNode.
Therefore you can get the selected node(s), not node's subitems.

You can obtain the selected node by SelectedNodes property.

Here is a small example:

//Filling NTreeList with some data.

NTreeListColumn column0 = new NTreeListColumn();
NTreeListColumn column1 = new NTreeListColumn();

nTreeList1.Columns.Add(column0);
nTreeList1.Columns.Add(column1);

for (int i = 0; i < 5; i++)
{
    NTreeListNode node = new NTreeListNode();
   
NTreeListNodeStringSubItem item0 = new NTreeListNodeStringSubItem("Item 0" + i.ToString());
    item0.Column = column0;

   
NTreeListNodeStringSubItem item1 = new NTreeListNodeStringSubItem("Item 1" + i.ToString());
    item1.Column = column1;

    node.SubItems.Add(item0);
    node.SubItems.Add(item1);

    nTreeList1.Nodes.Add(node);
}

After select some nodes you can get them as follows:

NTreeNode[] selectedNodes = nTreeList1.SelectedNodes;

Since, the array items are of type NTreeNode you should cast to NTreeListNode to get node's subitems.

By Ignacio Mendiguren - Monday, October 10, 2011

Hi,

If I understood, using

NTreeNode[] selectedNodes = nTreeList1.SelectedNodes

I get all nodes selected, but how can I get the subitem selected?

Thanks

IM

By Ignacio Mendiguren - Monday, October 10, 2011

Hi,

I found the answer. By doing

Dim a = DirectCast(selectedNodes(0), Nevron.UI.WinForm.Controls.NTreeListNode).SubItems(0).RawData

I get the value of the first column of the row selected.

Thanks and regards,

 

IM