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

RadtreeView within RadgridView

9 Answers 422 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Somnath
Top achievements
Rank 1
Somnath asked on 18 Jan 2011, 03:18 PM
HI,

In my application, I want RadtreeView  in  one of the column of  radgridview.
When user click perticular columns cell then RadTreeView Should be populate..
And User should be able to select any node(value) from the Radtreeview (having datasource) which
will be the cells value......
Is it possible in Radgridview?

Thanks.....

9 Answers, 1 is accepted

Sort by
0
Jack
Telerik team
answered on 21 Jan 2011, 08:53 AM
Hi Somnath,

Yes, it is possible to host a RadTreeView control in RadGridView cells. However, controls are slow and using a lot of them can slow down the grid and will cause visual glitches when scrolling. This is because controls cannot be clipped in WinForms. Could you please elaborate a bit more and describe in detail what exactly you want to achieve. We will be glad to find the best option in this case.

I am looking forward to your reply.

Best wishes,
Jack
the Telerik team
Q3’10 SP1 of RadControls for WinForms is available for download; also available is the Q1'11 Roadmap for Telerik Windows Forms controls.
0
Somnath
Top achievements
Rank 1
answered on 24 Jan 2011, 07:56 AM
Hello,

In this Case, I have a gridview which contain four columns--- Company (GridViewComboBoxColumn),Account(GridViewComboBoxColumn),,Memo(GridViewTextBoxColumn), and CustomerType(GridViewComboBoxColumn),.
In Account column,there is 47 different Accounts----
15 belongs to Expence Type-- e.g( [Expence] Rent Expence)
15 Belongs to Income Type--e.g([Income] Investment Income)
15 Belongs to Bank Type-- e.g([Bank] Cash Account1)
2 Belongs to Other Type--  e.g([Other] Other CurrentLiab.)

But, I want-- when user click Account column ,it should display Radtreeview with
----Expence Type
    Income Type
    Bank Type
    Other Type . options(node)

And when click any Type then it should display perticular Types Accounts Only....

Waiting for your reply.....

Thank You
0
Jack
Telerik team
answered on 26 Jan 2011, 10:57 AM
Hello Somnath,

In this case you can show a custom editor which will open the tree view control as popup. I prepared a small example, please check the code below:
void radGridView1_EditorRequired(object sender, EditorRequiredEventArgs e)
{
    if (this.radGridView1.CurrentColumn.Name == "Name")
    {
        e.EditorType = typeof(TreeEditor);
    }
}
 
public class TreeEditor: BaseGridEditor
{
    public override object Value
    {
        get
        {
            TreeEditorElement treeElement = this.EditorElement as TreeEditorElement;
            RadTreeNode treeNode = treeElement.TreeView.SelectedNode;
            if (treeNode != null)
            {
                return treeNode.Text;
            }
            return "";
        }
        set
        {
            TreeEditorElement treeElement = this.EditorElement as TreeEditorElement;
            RadTreeNode treeNode = FindTreeNode(treeElement.TreeView.Nodes[0], value as string);
            if (treeNode != null)
            {
                treeNode.Selected = true;
                treeElement.Button.Text = value as string;
            }
            else
            {
                treeElement.Button.Text = "";
            }
        }
    }
 
    public override void BeginEdit()
    {
        base.BeginEdit();
        TreeEditorElement treeElement = this.EditorElement as TreeEditorElement;
        treeElement.Button.ShowDropDown();
    }
 
    protected override RadElement CreateEditorElement()
    {
        return new TreeEditorElement();
    }
 
    private RadTreeNode FindTreeNode(RadTreeNode node, string value)
    {
        if (node.Text == value)
        {
            return node;
        }
        foreach (RadTreeNode subNode in node.Nodes)
        {
            RadTreeNode found = FindTreeNode(subNode, value);
            if (found != null)
            {
                return found;
            }
        }
        return null;
    }
}
 
public class TreeEditorElement: RadHostItem
{
    public TreeEditorElement(): base(new RadDropDownButton())
    {
        this.Button.Items.Add(new TreeMenuItem());
        TreeView.MouseUp += new MouseEventHandler(treeView_MouseUp);
        TreeView.Nodes.Add(new RadTreeNode("Root"));
        TreeView.Nodes[0].Nodes.Add(new RadTreeNode("Item 1"));
        TreeView.Nodes[0].Nodes.Add(new RadTreeNode("Item 2"));
        TreeView.ExpandAll();
    }
 
    void treeView_MouseUp(object sender, MouseEventArgs e)
    {
        this.Button.HideDropDown();
        (this.Parent as GridCellElement).GridViewElement.EditorManager.EndEdit();
    }
 
    public RadDropDownButton Button
    {
        get { return (RadDropDownButton)this.HostedControl; }
    }
 
    public RadTreeView TreeView
    {
        get { return (RadTreeView)((RadMenuHostItem)this.Button.Items[0]).HostedControl; }
    }
}
 
public class TreeMenuItem: RadMenuHostItem
{
    public TreeMenuItem(): base(new RadTreeView()) {}
 
    protected override SizeF MeasureOverride(SizeF availableSize)
    {
        base.MeasureOverride(availableSize);
        return new SizeF(100, 100);
    }
}

I hope this helps. If you have further questions, do not hesitate to ask.

Greetings,
Jack
the Telerik team
Q3’10 SP1 of RadControls for WinForms is available for download; also available is the Q1'11 Roadmap for Telerik Windows Forms controls.
0
Somnath
Top achievements
Rank 1
answered on 27 Jan 2011, 12:16 PM
Hello,

Please, let me know how to bind Data Source to nodes of treeview
with Example.

Thank You
0
Accepted
Julian Benkov
Telerik team
answered on 01 Feb 2011, 01:26 PM
Hi Somnath,

You can bind the RadTreeView editor control using the DataSource property. Here is a simple example using the Employee table from the AdventureWorks database:

private void button2_Click(object sender, EventArgs e)
{
    treeElement.TreeView.DataSource = this.employeeBindingSource;
 
    treeElement.TreeView.DisplayMember = "Title";
    treeElement.TreeView.ParentIDMember = "ManagerID";
    treeElement.TreeView.ValueMember = "EmployeeID";
    treeElement.TreeView.FullRowSelect = true;
}

Kind regards,
Julian Benkov
the Telerik team

Q3’10 SP1 of RadControls for WinForms is available for download; also available is the Q1'11 Roadmap for Telerik Windows Forms controls.
0
Mohamed
Top achievements
Rank 1
answered on 21 Oct 2013, 12:43 PM
How can i get the treeview control from  radgridview row ?

what i want is to get the nodes that have been selected for every row in the radgridview 

if there's a code about how i can do this , i will be appreciated 
0
Dess | Tech Support Engineer, Principal
Telerik team
answered on 24 Oct 2013, 11:09 AM
Hello Mohamed,

Thank you for contacting Telerik Support.

Please find attached a sample project implementing the functionality demonstrated in the attached video (drag and drop over the browser to play). Note that you have access to the treeview in edit mode only.

I hope this information helps. Should you have further questions, I would be glad to help.

Regards,
Desislava
Telerik
TRY TELERIK'S NEWEST PRODUCT - EQATEC APPLICATION ANALYTICS for WINFORMS.
Learn what features your users use (or don't use) in your application. Know your audience. Target it better. Develop wisely.
Sign up for Free application insights >>
0
Mohamed
Top achievements
Rank 1
answered on 06 Nov 2013, 12:07 PM
that is not what i wanted
i have a radgridview that has a column of type GridViewComboBoxColumn that itself has a treeview in it ,i followed the example in this post of how i can add a treeview in radgridview , and it works just fine ,now i want to iterate over the radgridview rows to get the selected nodes in the treeview for each row , so i can save the nodes' id to the Database when i click save button

how can i do that ?

thanks in advance

0
Dess | Tech Support Engineer, Principal
Telerik team
answered on 11 Nov 2013, 08:37 AM
Hello Mohamed,

Thank you for writing back.

The provided example in this forum thread concerns modifying the default editor with inserting a RadTreeView in the drop down list only. As I explained in my previous post, you have access to the exact tree view in edit mode only. You can not get the selected nodes for each row. In the current sample version, TreeEditor.Value is modified according to each node.Text. After edit operation has been finished, you can modify cell value on a way to indicate which are the selected nodes and to be able to save their IDs in a database. The other option that you have is to implement a custom cell which can achieve your exact requirement. You can find more information about custom cells in our Creating custom cells help article.

I hope this information helps. Please do not hesitate to contact us if you have any additional questions.

Regards,
Desislava
Telerik
TRY TELERIK'S NEWEST PRODUCT - EQATEC APPLICATION ANALYTICS for WINFORMS.
Learn what features your users use (or don't use) in your application. Know your audience. Target it better. Develop wisely.
Sign up for Free application insights >>
Tags
GridView
Asked by
Somnath
Top achievements
Rank 1
Answers by
Jack
Telerik team
Somnath
Top achievements
Rank 1
Julian Benkov
Telerik team
Mohamed
Top achievements
Rank 1
Dess | Tech Support Engineer, Principal
Telerik team
Share this question
or