2016-03-24 28 views

cevap

1

Sen TreeView ait AfterSelect olaya abone olabilirsiniz: Normalde ilgili model örneğine TreeNode arasında Tag özelliğini ayarlayın

public partial class Form1 
{ 
    private TreeView treeView1; 
    private TextBox textBox1; 
    // ... shortened example 

    public Form1() 
    { 
     InitializeComponent(); 
     treeView1.AfterSelect += treeView1_AfterSelect; 
     //... 
    } 

    private void TreeView1_AfterSelect(object sender, TreeViewEventArgs e) 
    { 
     string description = string.Empty; 
     TreeNode node = treeView1.SelectedNode; 
     if (node != null) 
      description = // determine the text from your country data 

     textBox1.Text = description; 
    } 
} 

. Eğer bu şekilde bir Country sınıf var ise:

Country country = new Country { Name = "SomeCountry", Description = "description" }; 
TreeNode nextNode = new TreeNode(country.Name); 
nextNode.Tag = country; 
parentNode.Nodes.Add(nextNode); 

Ve AfterSelect işleyicisi aşağıdaki gibi görünebilir:

public class Country 
{ 
    public string Name { get; set; } 
    public string Description { get; set; } 
} 

Böyle TreeNodes eklersiniz

private void TreeView1_AfterSelect(object sender, TreeViewEventArgs e) 
    { 
     textBox1.Text = (treeView1.SelectedNode?.Tag as Country)?.Description ?? string.Empty; 
    } 
İlgili konular