Hi Ignacio,
You cannot do this with default state of the control.
However, if you are binding your data to NTreeList control you can subclass NTreeListTableData in order to build the nodes and subitems of NTreeList to look like you described.
I made an example which is doing that, but the source is strongly tided with the data structure and if the data structure changes it may not work correctly.
First lets create a DataTable with your data:
private
DataTable LoadTable()
{
DataTable table = new DataTable();
DataColumn column1 = new DataColumn("Name");
DataColumn column2 = new DataColumn("SurName");
DataColumn column3 = new DataColumn("Car");
table.Columns.AddRange(new DataColumn[] { column1, column2, column3 });
DataRow row0 = table.NewRow();
row0[0] = "John";
row0[1] = "Braun";
row0[2] = "Audi A6";
table.Rows.Add(row0);
DataRow row1 = table.NewRow();
row1[0] = "John";
row1[1] = "Braun";
row1[2] = "Mercedes SLK";
table.Rows.Add(row1);
DataRow row2 = table.NewRow();
row2[0] = "Thomas";
row2[1] = "Silvester";
row2[2] = "Volkswagen Passat 2.0";
table.Rows.Add(row2);
DataRow row3 = table.NewRow();
row3[0] = "Monica";
row3[1] = "Dufreau";
row3[2] = "Ford Fiesta";
table.Rows.Add(row3);
table.DefaultView.Sort = "Name, SurName DESC";
return table;
}Then create new class that derives from NTreeListTableData and override PopulateRows method:
public
class MyNTreeListData : NTreeListTableData
{
protected override void PopulateRows()
{
DataView view = Table.DefaultView;
int count = view.Count;
DataRowView row;
DataRowView temp = null;
NTreeListNode tempNode = null;
for (int i = 0; i < count; i++)
{
row = view[i];
string row2 = string.Empty;
if (i == 0)
{
tempNode = GetRow(row.Row);
row2 = row.Row[2].ToString();
AddSubNode(row2, tempNode);
temp = row;
continue;
}
if (row.Row[0] != temp.Row[0] || row.Row[1] != temp.Row[1])
{
Owner.Nodes.Add(tempNode);
tempNode = GetRow(row.Row);
}
else
{
row2 = row.Row[2].ToString();
AddSubNode(row2, tempNode);
temp = row;
continue;
}
row2 = row.Row[2].ToString();
AddSubNode(row2, tempNode);
temp = row;
}
Owner.Nodes.Add(tempNode);
}
protected void AddSubNode(string nodeText, NTreeListNode node)
{
NTreeListNode subNode = new NTreeListNode();
NTreeListNodeStringSubItem subitem = new NTreeListNodeStringSubItem(nodeText);
subitem.Column = Owner.Columns[2];
subNode.SubItems.Add(subitem);
node.Nodes.Add(subNode);
}
protected NTreeListNode GetRow(DataRow row)
{
NTreeListNode node = new NTreeListNode();
object[] values = row.ItemArray;
object value;
int length = values.Length;
NTreeListNodeSubItem item;
for (int i = 0; i < length - 1; i++)
{
value = values[i];
item = CreateSubItem(value);
item.Column = Owner.Columns[i];
node.SubItems.Add(item);
}
return node;
}
}Finally, all you need is to bind NTreeList to the data using the new class:
MyNTreeListData
data = new MyNTreeListData();
data.Table = LoadTable();
data.Bind(nTreeList1);Ones again I want to mension that this example implementation applies only for specific structure of your data.
I hope this helps.
Best Regards,
Nevron Support Team