DataBinding in Windows Forms TreeMap control

2 Jun 20211 minute to read

TreeMap control supports Data Binding and it can be achieved using ItemsSource property.

The ItemsSource property accepts the collection values as input. For example, you can provide the list of objects as input. The following code illustrates you on how to bind a flat collection as items source for TreeMap.

  • c#
  • public partial class Form1 : Form
    
        {
    
    	TreeMap TreeMap1 = new TreeMap();
    
    	public Form1()
    
            {
    
                InitializeComponent();
    
    
    
                PopulationViewModel data = new PopulationViewModel();
    
                TreeMap1.ItemsSource = data.PopulationDetails;
    
                TreeMap1.ColorValuePath = "Growth";
    
                This.Controls.Add(TreeMap1);
    
           }
    
       }

    Note: The specified field must be available in each and every sub class (object) defined in hierarchical (nested) data collection.