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

Contruction Nodes

7 Answers 64 Views
TreeView
This is a migrated thread and some comments may be shown as answers.
Caio
Top achievements
Rank 1
Caio asked on 16 Jul 2013, 12:03 PM
Hi! I have an page with Telerik that uses TreeView concept.
I use GroupByExpression to construct nodes. But I need construct in my C# an logic that transform an row in SQL with Folders Path in an line in my GridView.
Ex:
In my SQL I have an column FolderPath and value is "N:\Test\Drive\FolderTest".
I need transform this in nodes, or grouping this to ex:

- N:\
  - Test\
    - Drive\
      -FolderTest\

How I make it (Nodes or Grouping) in C#?

Below is my aspx actual.
<form id="form1" runat="server">
<Telerik:RadScriptManager runat="server" ID="RadScriptManager1" />
<Telerik:RadSkinManager ID="QsfSkinManager" runat="server" ShowChooser="false" />
<Telerik:RadFormDecorator ID="QsfFromDecorator" runat="server" DecoratedControls="All"
    EnableRoundedCorners="false" />
<Telerik:RadAjaxManager ID="RadAjaxManager1" runat="server">
    <AjaxSettings>
        <Telerik:AjaxSetting AjaxControlID="RadGrid1">
            <UpdatedControls>
                <Telerik:AjaxUpdatedControl ControlID="RadGrid1" LoadingPanelID="RadAjaxLoadingPanel1">
                </Telerik:AjaxUpdatedControl>
            </UpdatedControls>
        </Telerik:AjaxSetting>
    </AjaxSettings>
</Telerik:RadAjaxManager>
<Telerik:RadAjaxLoadingPanel ID="RadAjaxLoadingPanel1" runat="server">
</Telerik:RadAjaxLoadingPanel>
<div align="center" style="width: auto; height: auto;">
    <img src="image/NdriveBanner.png" align="center" />
</div>
<br />
<br />
<Telerik:RadGrid ID="RadGrid1" DataSourceID="SqlDataSource1" runat="server" AllowSorting="True"
    AllowPaging="True" AutoGenerateColumns="False" GridLines="None">
    <PagerStyle Mode="NumericPages"></PagerStyle>
    <MasterTableView Width="100%" GroupLoadMode="Client" TableLayout="Fixed" GroupsDefaultExpanded="false">
        <PagerStyle Visible="false" />
        <GroupByExpressions>
            <Telerik:GridGroupByExpression>
                <SelectFields>
                    <Telerik:GridGroupByField FieldAlias="REGION" FieldName="REGION"></Telerik:GridGroupByField>
                </SelectFields>
                <GroupByFields>
                    <Telerik:GridGroupByField FieldName="REGION"></Telerik:GridGroupByField>
                </GroupByFields>
            </Telerik:GridGroupByExpression>
            <Telerik:GridGroupByExpression>
                <SelectFields>
                    <Telerik:GridGroupByField FieldAlias="MARKET" FieldName="MARKET"></Telerik:GridGroupByField>
                </SelectFields>
                <GroupByFields>
                    <Telerik:GridGroupByField FieldName="MARKET"></Telerik:GridGroupByField>
                </GroupByFields>
            </Telerik:GridGroupByExpression>
            <Telerik:GridGroupByExpression>
                <SelectFields>
                    <Telerik:GridGroupByField FieldAlias="LOCATIONNAME" FieldName="LOCATIONNAME"></Telerik:GridGroupByField>
                </SelectFields>
                <GroupByFields>
                    <Telerik:GridGroupByField FieldAlias="LOCATIONNAME" FieldName="LOCATIONNAME"></Telerik:GridGroupByField>
                </GroupByFields>
            </Telerik:GridGroupByExpression>
        </GroupByExpressions>
        <Columns>
            <Telerik:GridBoundColumn SortExpression="REGION" HeaderText="REGION" HeaderButtonType="TextButton"
                DataField="REGION">
            </Telerik:GridBoundColumn>
            <Telerik:GridBoundColumn SortExpression="MARKET" HeaderText="MARKET" HeaderButtonType="TextButton"
                DataField="MARKET">
            </Telerik:GridBoundColumn>
            <Telerik:GridHyperLinkColumn DataNavigateUrlFields="IDSERVER" DataNavigateUrlFormatString="PathFolders.aspx?idServer={0}"
                DataTextField="LOCATIONNAME" FilterControlAltText="Filter column column" HeaderText="LOCATION NAME"
                UniqueName="column">
                <ItemStyle HorizontalAlign="Left" />
            </Telerik:GridHyperLinkColumn>
            <Telerik:GridBoundColumn SortExpression="SERVERNAME" HeaderText="SERVER NAME" HeaderButtonType="TextButton"
                DataField="SERVERNAME">
            </Telerik:GridBoundColumn>
        </Columns>
    </MasterTableView>
    <ClientSettings ReorderColumnsOnClient="True" AllowDragToGroup="True" AllowColumnsReorder="True">
        <ClientEvents OnGridCreated="demo.GridCreated" />
    </ClientSettings>
    <GroupingSettings ShowUnGroupButton="true"></GroupingSettings>
</Telerik:RadGrid>
<br />
<asp:SqlDataSource ID="SqlDataSource1" ConnectionString="<%$ ConnectionStrings:dbNDriveSecurityConnectionString %>"
    ProviderName="System.Data.SqlClient" SelectCommand="SELECT IDLOCATION,REGION,MARKET,LOCATIONNAME,SERVERNAME,IDSERVER FROM LOCATIONS L INNER JOIN [SERVERS] S ON l.LocationCode = s.LocationCode ORDER BY Region,Market,LocationName,ServerName"
    runat="server"></asp:SqlDataSource>
</form>

7 Answers, 1 is accepted

Sort by
0
Boyan Dimitrov
Telerik team
answered on 19 Jul 2013, 11:40 AM
Hello,

An easy and convenient way of achieving such functionality would be to parse the response of your SQL query by the character "/" and add each next string element in that collection as a child of the previous one.


Regards,
Boyan Dimitrov
Telerik
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to the blog feed now.
0
Caio
Top achievements
Rank 1
answered on 19 Jul 2013, 11:53 AM
Tks for your answer. But, I'm begginer. What I can make this in my cs? I have an column "sub_folderpath" that have full path for each folder. How I transform this full path in nodes/subnodes for each "/" character, and inform to aspx that it's to grouping? I'm clear? In time, I need an answers for emails that I sent to sales area! You can help my? Tks for all!
0
Boyan Dimitrov
Telerik team
answered on 24 Jul 2013, 11:28 AM
Hello,

Please find attached a sample project implementing a very similar scenario - a folder path is parsed and visualized  as tree-view structure using our RadTreeView control.
//markup code
<telerik:RadTreeView ID="RadTreeView1" runat="server">
 
</telerik:RadTreeView>
//code behind
protected void Page_Load(object sender, EventArgs e)
    {
        if (!Page.IsPostBack)
        {
            string folderPath = "N:\\Test\\Drive\\FolderTest";
            ParseFolderPath(folderPath);
        }
    }
 
    private void ParseFolderPath(string path)
    {
        string[] separateNodes = path.Split('\\');
 
        for (int i = 0; i < separateNodes.Length; i++)
        {
            
            if (i == 0)
            {
                RadTreeNode currentNode = new RadTreeNode(separateNodes[i]);
                RadTreeView1.Nodes.Add(currentNode);
            }
            else
            {
                RadTreeNode childNode = RadTreeView1.Nodes[0];
                 
                for (int j = 0; j < i; j++)
                {
                    if (childNode.Nodes.Count <= 0)
                    {
                        childNode.Nodes.Add(new RadTreeNode());
                    }
                    childNode = childNode.Nodes[0];
                     
                    if (j == i - 1)
                    {
                        childNode.Text = separateNodes[i];
                    }
                }
            }
        }
    }


Regards,
Boyan Dimitrov
Telerik
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to the blog feed now.
0
Caio
Top achievements
Rank 1
answered on 24 Jul 2013, 12:42 PM
I can transform this RadTreeView in an RadGridView? And, I set this string in a foreach, but work just for the first row. I'm trying adapting it. Tks! Attached, I have my actual RadGridView and my TreeView with your code. I need an "treeview" mode to Sub Folder Path but with my GridView template.
0
Boyan Dimitrov
Telerik team
answered on 29 Jul 2013, 01:07 PM
Hello,

I would like to clarify that our RadGrid Hierarchy with Templates demo implements very similar scenario. In your case you can use a RadTreeView control inside the NestedViewTemplate instead of RadTabStrip with RadMultiPage with nested RadGrid control as shown in the example. That way you can bind the RadTreeView control to the GridColumn and use the provided logic for iterating and adding nodes based on the folder path from my last response.  

Regards,
Boyan Dimitrov
Telerik
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to the blog feed now.
0
Caio
Top achievements
Rank 1
answered on 22 Aug 2013, 12:55 PM
Hello!!
I have a list with my all folders. My list have 35 rows.
But, when I do nodes, it's made in just one folder.

For example:

"N:\ALPINO_00" is my first row in my list (listLocations[0]) but in my page, just my row 35 (listLocations[34]) have nodes.
for all others rows, show just "N".
"N:\Mathias\level2\level3"

-N
--Mathias
------------Level2
---------------------Level3
I'm clear? Well, when I make my "ParseFolderPath"  build nodes for all rows?



protected void Page_Load(object sender, EventArgs e)
    {
        if (!Page.IsPostBack)
        {
            var listLocations = new List<string>();
            using (objConexao = new SqlConnection(strStringConexao))
            {
                using (objCommand = new SqlCommand(strListProfile, objConexao))
                {
                    try
                    {
                        objConexao.Open();
                        var objDataReader = objCommand.ExecuteReader();
 
                        if (objDataReader.HasRows)
                        {
                            while (objDataReader.Read())
                            {
                                listLocations.Add(objDataReader.GetString(0));
                            }
                        }
                    }
                    finally
                    {
                        objConexao.Close();
                    }
                }
            }
            listLocations.ToList();
            ParseFolderPath(listLocations);
        }
    }
 
    private void ParseFolderPath(List<string> paths)
    {
        paths.ForEach(path =>
            {
                string[] separateNodes = path.Split('\\');
                for (int i = 0; i < separateNodes.Length; i++)
                {
 
                    if (i == 0)
                    {
                        RadTreeNode currentNode = new RadTreeNode(separateNodes[i]);
                        RadTreeView1.Nodes.Add(currentNode);
                    }
                    else
                    {
                        RadTreeNode childNode = RadTreeView1.Nodes[0];
 
                        for (int j = 0; j < i; j++)
                        {
                            if (childNode.Nodes.Count <= 0)
                            {
                                childNode.Nodes.Add(new RadTreeNode());
                            }
                            childNode = childNode.Nodes[0];
 
                            if (j == i - 1)
                            {
                                childNode.Text = separateNodes[i];
                            }
                        }
                    }
                }
            });
    }
0
Boyan Dimitrov
Telerik team
answered on 27 Aug 2013, 10:34 AM
Hello,

Please find attached a sample of very similar scenario implementation - the RadTreeView control is placed within a MasterViewTable NestedViewTemplate and it could be accessed in order to pass the path string and executed the parsing functionality.

Please expand a random row and then start interacting with the RadTreeView showing hierarchy structure of the passed path argument. 

Regards,
Boyan Dimitrov
Telerik
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to the blog feed now.
Tags
TreeView
Asked by
Caio
Top achievements
Rank 1
Answers by
Boyan Dimitrov
Telerik team
Caio
Top achievements
Rank 1
Share this question
or