how to customize the displayname using the data binding

2 posts, 0 answers
  1. Daniel
    Daniel avatar
    1 posts
    Member since:
    Jul 2011

    Posted 18 Aug 2011 Link to this post

    I have the following problem. 
    There is a table "Account" having following properties.
    Number -> prim key
    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;
    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
    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
    node -> 5678||nameTwo
  2. Stefan
    Stefan avatar
    2891 posts

    Posted 23 Aug 2011 Link to this post

    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,
    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 >>

  3. DevCraft R3 2016 release webinar banner
Back to Top