Numeric Key with Text in Tree Mapper

Hi Walter,

I am using Tree Mapper and generating two trees. I have to fetch the values from Database and then shown in the Trees. Suppose, I have Categories on Left showing the name of the categories and Products on the Right showing the names of the products. Currently, I am using Product Name as the Key. Can I give some unique Ids (Product ID) to the Key and add the Product Name as text so that Product Name is displayed to the user but Product ID is for our internal tree and its mapping generation?

I am using like this
var nodeDataArray = [
{ isGroup: true, key: -1, text:“Categories”, xy: “0 0” },
{ isGroup: true, key: -2, text: “Products”, xy: “0 0” }

var catKey = { key: CategoryName, group: -1 };

var prodKey = { key: ProductName, group: -2 };

Hope you understand my requirement. Can you please suggest how I can achieve the same?


Are your product names guaranteed to be unique? Are the category names unique? I assume yes within each set of strings.

Will the two sets of names always form distinct sets of strings?

If so, then you can just use the names as the keys.

If not, you could always prepend some identifier, such as “p” for product names and “c” for category names.

Hi Walter,
No, category name and product name are not unique. They can be of same name. So, I am getting the issue while generating the tree. If the same name exists then tree automatically add the numeric number after the name. Suppose, if IPad is a product name and it occurs 4 times, then the tree shows, IPad, IPad 1, IPad 2, IPad 3.

Also, I can’t prepend any identifier in the tree (as this is not the requirement of the customer means I have to show only the name) . So, is there any other way to solve this?

Your template does not have to show the key – it can show any text that you like, as many as you like, or none at all.

If you always prepend “p” or “c” to the key, then you can always remove that first character in a Binding converter when binding the TextBlock.text property to the “key”.