Telerik Forums
UI for WPF Forum
9 answers
1.1K+ views
Hi,

I'm having difficulty trying to build a multi level hierarchy that has unknown levels.
I've read loads and loads of examples but they all assume the number of levels are known. However, in my case I may have "x" number of nodes, which may have "x" number of child nodes, which may have "x" number of grandchild nodes etc etc.

My data is drawn from an SQL database where I use the SQL 2008 HierarchyID data type to represent my hierarchy in the database.

I've built the following class for my products:



public class Products : INotifyPropertyChanged, IDataErrorInfo
{
private Int64 m_ID;
private SqlHierarchyId m_Hierarchy;
private string m_Name;
private Int16 m_Level;
private ObservableCollection<Products> m_ChildProducts;
// Default Constructor
public Products()
{
ChildProducts = new ObservableCollection<Products>();
}
//Properties
public Int64 ID
{
get
{
return m_ID;
}
set
{
m_ID = value;
OnPropertyChanged(new PropertyChangedEventArgs("ID"));
}
}
public SqlHierarchyId Hierarchy
{
get
{
return m_Hierarchy;
}
set
{
m_Hierarchy = value;
OnPropertyChanged(new PropertyChangedEventArgs("Hierarchy"));
}
}
public Int16 Level
{
get
{
return m_Level;
}
set
{
m_Level = value;
OnPropertyChanged(new PropertyChangedEventArgs("Level"));
}
}
public String Name
{
get
{
return m_Name;
}
set
{
m_Name = value;
OnPropertyChanged(new PropertyChangedEventArgs("Name"));
}
}
public ObservableCollection<Products> ChildProducts
{
get
{
return m_ChildProducts;
}
set
{
m_ChildProducts = value;
OnPropertyChanged(new PropertyChangedEventArgs("ChildProducts"));
}
}
//INotifyPropertyChanged Event
public event PropertyChangedEventHandler PropertyChanged;
public void OnPropertyChanged(PropertyChangedEventArgs e)
{
if (PropertyChanged != null)
PropertyChanged(this, e);
}
}


I then have the following method to download data from the database which I need to some how construct an ObservableCollection() which contains nodes "x" number of levels deep. Please note that some nodes may be 2 levels deep, others may be 3 levels deep, so forth and so forth.


public static ObservableCollection<Products> GetProductsHierarchy()
        {
            ObservableCollection<Products> products = new ObservableCollection<Products>();
 
            SqlConnection connection = new SqlConnection(DBConnection.GetConnection().ConnectionString);
 
            string selectStatement = "SELECT ID, Hierarchy, Name " +
                                     "FROM SpecProducts " +
                                     "WHERE (EnableDisable IS NULL)" +
                                     "ORDER BY Hierarchy";
 
            SqlCommand selectCommand = new SqlCommand(selectStatement, connection);
 
            try
            {
                connection.Open();
                SqlDataReader reader = selectCommand.ExecuteReader();
 
                while (reader.Read())
                {
                     
                    Products product = new Products();
                    product.ID = (Int64)reader["ID"];
                    product.Name = reader["Name"].ToString();
                    product.Hierarchy = (SqlHierarchyId)reader["Hierarchy"];
                    product.Level = (Int16)product.Hierarchy.GetLevel();
 
                    //**** How to create recursive loop to add unknown levels to nodes???? ****
 
                    products.Add(product);
                }
 
 
                return products;
            }
            catch (SqlException ex)
            {
                throw ex;
            }
            finally
            {
                connection.Close();
            }
        }


I've found a post that discusses unlimited nodes, http://www.telerik.com/community/forums/wpf/treeview/templated-node-multiple-parent.aspx , but in the example given it has the following lines of code to build up unlimited levels:
ObservableCollection<Node> nodes = new ObservableCollection<Node>();
 
nodes.Add(new Node("Company"));
nodes[0].Nodes.Add(new Node("Department"));
nodes[0].Nodes[0].Nodes.Add(new Node("here are you"));
nodes[0].Nodes[0].Nodes[0].Nodes.Add(new Node("even deeper"));
 
radTreeView1.ItemsSource = nodes;

Surely this is only valid providing you know the number of levels before runtime?


I guess I'm essentially looking for a generic hierarchy builder where the number of levels are unknown until runtime, i.e. when data is download from database.

Any help would be greatly appreciated.

Thanks for your time.


Ammar
Top achievements
Rank 1
 answered on 11 Dec 2018
1 answer
97 views

Hello,

This big can be reproduced in your demo application:

  1. Open the GridView examples
  2. In the available examples, select "Selection and Usability | Row Details"
  3. Select a rowin the grid view
  4. In the external Details Presenter, select Visible: nothing is displayed in the bottom. You have to select another row and then come back to show the details.

 

Also another problem: if the external details is inside a ContentPresenter (collapsed at the beginning), it can't find  the gridview.

To test this, replace your Border with a ContentPresenter.

Ivan Petrov
Telerik team
 answered on 10 Dec 2018
10 answers
193 views

I am currently using RAD shapes and Text on Rad Diagram Canvas in WPF

I would like to know I can get pixel view for two color Displays, like attached Image [296x128.PNG].

Currently I can see different effects are supported, can you please let me know how can I modify rad diagram canvas  to display two color (Black and White) mode, and also I need to then export it to monochrome bitmap.

Thanks.

 

Martin Ivanov
Telerik team
 answered on 10 Dec 2018
1 answer
71 views

Hello Expertise,

I want to use RadChartView control into my new project WPF.

But problem is that i can't see "RadChartView" into VS 20017 ToolBox. please need assistance.

 

Thanks,

Maksud

Martin Ivanov
Telerik team
 answered on 10 Dec 2018
2 answers
162 views

Hi,

I've got a problem with overlapping RadPanes when using RadDocking Root Compass.

The case is that when I'm dragging RadPanes to the one side of the Root Compass, the Rad Panes on the other side gets overlapped by the dragged ones.
Description may not be clear, so here is simple gif showing the problem:

Pane "Inner Pane C" get overlapped, when dragging new panes to the left side of the Root Compass. It works for every side of the Root Compass.

 

Is there a simple solution for this issue? Ex. modifying the docked Panes width, to fit them all in the RadDocking control? I've searched on this forum and in the documentation, and couldn't find the solution.

 

Best regards,

Mateusz

Dilyan Traykov
Telerik team
 answered on 07 Dec 2018
2 answers
393 views

Hello,

Could you, please, help me to make RadRichTextBox's caret visible?

I've tried to use solution with custom CaretFactory from this post... No results, unfortunately

Is it possible to make caret visible?

 

Here is some code examples of RadRichTextBox usage (my telerik version: 2018.3.911.45):

<telerik:RadRichTextBox x:Name="descriptionRichBox" 
            Grid.Row="0" Grid.Column="1" Margin="0,2,0,5"  MinHeight="70"      
 BorderThickness="{Binding IsReadOnly, Converter={localConverters:BoolToBorderThicknessConverter}}"
            FontSize="{Binding Source={StaticResource MediumNormal}, Path=Size}"
            FontFamily="{Binding Source={StaticResource MediumNormal}, Path=Family}"
            IsReadOnly="{Binding IsReadOnly}" GotFocus="RichTextBox_GotFocus"
            DocumentInheritsDefaultStyleSettings="True" IsSpellCheckingEnabled="False"
                                />
<telerik:HtmlDataProvider RichTextBox="{Binding ElementName=descriptionRichBox}"
    Html="{Binding EditableObject.Description, Mode=TwoWay}"       
                                  />
<Style TargetType="telerik:Caret">
  <Setter Property="Template">
        <Setter.Value>
            <ControlTemplate TargetType="telerik:Caret" >
                <Grid x:Name="RootElement"  >
                    <ScrollViewer   x:Name="ContentElement" BorderThickness="0" Padding="0" />
                            <Rectangle x:Name="Rectangle" />
                </Grid>
            </ControlTemplate>
        </Setter.Value>
    </Setter>
    <Setter Property="HorizontalAlignment" Value="Left" />
    <Setter Property="VerticalAlignment" Value="Top" />
    <Setter Property="AcceptsReturn" Value="True" />
    <Setter  Property="CaretBrush" Value="Black"/>
    <Setter Property="Padding" Value="0" />
    <Setter Property="Foreground" Value="Transparent" />
</Style>
public class DescriptionCaretFactory : ICaretFactory
    {
        public Caret CreateCaret()
        {
            return new Caret { Width = 2, MinWidth = 2, Height=5,
                IsBlinking = true, IsEnabled = true,
                Visibility = System.Windows.Visibility.Visible,
                ToolTip = "test caret",
                CaretBrush = System.Windows.Media.Brushes.Black, };
        }
    }

 

Best regards,

Ivan.

Ivan
Top achievements
Rank 1
 answered on 07 Dec 2018
1 answer
378 views

I have created a Telerik.Windows.Documents.Spreadsheet.Model.Workbook (with a single Worksheet) programmatically. I can export it to Excel no problem.

How can I print it?

I have found the following article: https://docs.telerik.com/devtools/wpf/controls/radspreadsheet/features/ui-printing#How_to_print_RadSpreadsheet

...but this would force me to work with the UI Control, which I don't want to do. Is it possible to print the Worksheet without the use of the UI control. I still want all the printing options, such as setting a header and footer, forcing the first row to be repeated on every page, control over portrait vs. landscape printing, etc.

Is there any way to do this?

Thanks in advance,

Bartek

Martin
Telerik team
 answered on 06 Dec 2018
2 answers
66 views

There was an old post about this but I've never been able to find it. At high zoom levels (20 and 21), the Aerial mode usually doesn't show images. Other modes show a zoomed-in version of the previous images, including AerialOnDemand. There doesn't seem to be a way not show labels with AerialOnDemand, unfortunately. Can Aerial be changed so that it also shows the zoomed-in previous images?

Bing documentation says: "Note: Some imagery may not be available at all zoom levels for all locations. If imagery is not available at a location, a message is returned in the ErrorDetails collection of the response."
Vladimir Stoyanov
Telerik team
 answered on 06 Dec 2018
1 answer
123 views
Hi. 
I have a program that in some cases need to show 20+ charts, each with 20 000+ data points, and the charts can be manipulated with pan and zoom so that every chart changes simultaneously. It also needs to have dynamic sampling so that the charts are simplified when displaying many points, but show detail when zoomed in. It works fine when panning, all the charts update smoothly. However when I zoom in or out, I need to change the chartdatasource sampling threshold to adjust the detail, and this is very slow. It takes several seconds for the operation to complete and all charts to update. Why does this take so long and is there any way to speed up the operation?
Dinko | Tech Support Engineer
Telerik team
 answered on 06 Dec 2018
1 answer
313 views

Why isn't it possible to set the background to transparent?

It always shows it white or another color you set but not transparent

Dilyan Traykov
Telerik team
 answered on 06 Dec 2018
Narrow your results
Selected tags
Tags
+? more
Top users last month
Will
Top achievements
Rank 2
Iron
Motti
Top achievements
Rank 1
Iron
Hester
Top achievements
Rank 1
Iron
Bob
Top achievements
Rank 3
Iron
Iron
Veteran
Thomas
Top achievements
Rank 2
Iron
Want to show your ninja superpower to fellow developers?
Top users last month
Will
Top achievements
Rank 2
Iron
Motti
Top achievements
Rank 1
Iron
Hester
Top achievements
Rank 1
Iron
Bob
Top achievements
Rank 3
Iron
Iron
Veteran
Thomas
Top achievements
Rank 2
Iron
Want to show your ninja superpower to fellow developers?
Want to show your ninja superpower to fellow developers?