Fails to generate treemap from datatable

Hello,
I am new to Syncfusion components and especially the treemap control
I am trying to generate a treemap from a datatable with the following code (VB.NET on .NET Framework 4.5)

Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click

        Dim dtDashboard As DataTable = New DataTable
        dtDashboard.Columns.Add("Continent", Type.GetType("System.String"))
        dtDashboard.Columns.Add("Country", Type.GetType("System.String"))
        dtDashboard.Columns.Add("Users", Type.GetType("System.Int32"))

        dtDashboard.Rows.Add("Europe", "France", 13)
        dtDashboard.Rows.Add("Europe", "Germany", 8)
        dtDashboard.Rows.Add("Europe", "Switzerland", 7)
        dtDashboard.Rows.Add("Asia", "Singapore", 5)
        dtDashboard.Rows.Add("Asia", "Thailand", 2)

        TreeMap1.ItemsSource = dtDashboard 'fails with the below error message

        Dim tmft1 As New TreeMapFlatLevel
        tmft1.GroupPath = "Continent"
        tmft1.ShowLabels = True
        TreeMap1.Levels.Add(tmft1)

        Dim tmft2 As New TreeMapFlatLevel
        tmft2.GroupPath = "Country"
        tmft2.ShowLabels = True
        TreeMap1.Levels.Add(tmft2)

        TreeMap1.WeightValuePath = "Users"

    End Sub

-----------------------

error message

System.ArgumentNullException was unhandled
  HResult=-2147467261
  Message='name' argument cannot be null.
Parameter name: name
  ParamName=name
  Source=System.Data
  StackTrace:
       at System.Data.DataColumnCollection.get_Item(String name)
       at System.Data.DataRowView.get_Item(String property)
       at Syncfusion.Windows.Forms.TreeMap.TreeMapEngine.GetGroupItem(String field, String labelPath)
       at Syncfusion.Windows.Forms.TreeMap.TreeMap.GenerateTreeMapItems()
       at Syncfusion.Windows.Forms.TreeMap.TreeMap.OnPaint(PaintEventArgs e)
       at System.Windows.Forms.Control.PaintWithErrorHandling(PaintEventArgs e, Int16 layer)
       at System.Windows.Forms.Control.WmPaint(Message& m)
       at System.Windows.Forms.Control.WndProc(Message& m)
       at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
       at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
       at System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
  InnerException: 

----

I just can not figure out which missing 'name' the error is referencing
The same datatable loads fine in a datagridview
Any pointer much apreciated

Best regards,
Cyril


2 Replies

CH Cyril Hauppert December 15, 2017 09:21 AM UTC

Managed to solve the problem

The approach failed for the following reasons:
- I had previously added the Treemap1 manually to the form before assigning the 'itemsource' which fails. The control can only be added after the itemsource and other properties are set
- Some of the properties such as the ColorValuePath are required and the process fails if no value is provided


SG Sri Gayathri Gopalakrishnan Syncfusion Team December 15, 2017 10:29 AM UTC

Hi Cyril ,

we are glad to know that the issue has been resolved and please get back to us if you need any other assistance.

Regards,
Sri Gayathri.G

Loader.
Up arrow icon