This is a migrated thread and some comments may be shown as answers.

how to customize the displayname using the data binding

1 Answer 113 Views
Treeview
This is a migrated thread and some comments may be shown as answers.
Daniel
Top achievements
Rank 1
Daniel asked on 18 Aug 2011, 01:47 PM
I have the following problem. 
There is a table "Account" having following properties.
Number -> prim key
ParentNumber
Name
Description
isParent -> flag indicating if parent

I'm trying to bind this table with the radtreeview. Using the code:

  RadTreeView treeView = this.mView.AccountTreeView;
           
            treeView.DisplayMember = "Name";
            treeView.ParentMember = "ParentNumber";
            treeView.ChildMember = "Number";
            treeView.DataSource = this.mDataSet.Account;
           
            treeView.ExpandAll();
This works well and I have the treehierarchy (self referencing), but I would like to customize the displayMember, that not only the name is showned 
but the combination between the name and number. For example
Name = justname
Number=112222
What I need are the nodes looking like this 
node -> 22222||justname
As you can see it is not just the merging these two fields but also cutting of the first two digits from the number
Another case:
Name = nameTwo
Number=335678
node -> 5678||nameTwo

1 Answer, 1 is accepted

Sort by
0
Stefan
Telerik team
answered on 23 Aug 2011, 09:02 AM
Hi Daniel,

Thank you for writing.

You can achieve the desired behavior by handling the NodeFormatting event. When handling the event, get the desired strings and set the Text property of TreeNodeContentElement. The following code concatenates the Text property with the value of the "pid" column:

void radTreeView1_NodeFormatting(object sender, Telerik.WinControls.UI.TreeNodeFormattingEventArgs e)
{
    DataRowView view = (DataRowView)e.Node.DataBoundItem;
    string s = view.Row["pid"].ToString();
    if (s != string.Empty)
    {
        e.NodeElement.ContentElement.Text = e.Node.Text + " | " + s;
    }
}

I hope that you find this information helpful. Should you have any other questions, do not hesitate to contact us.
 
All the best,
Stefan
the Telerik team

Thank you for being the most amazing .NET community! Your unfailing support is what helps us charge forward! We'd appreciate your vote for Telerik in this year's DevProConnections Awards. We are competing in mind-blowing 20 categories and every vote counts! VOTE for Telerik NOW >>

Tags
Treeview
Asked by
Daniel
Top achievements
Rank 1
Answers by
Stefan
Telerik team
Share this question
or