I’m building a treeview legend and I wanted to extract the layer category for the treeview node that received the information I need help please because there was a conflict on node 1;
<code source button 1 for treeview:
public void button1_Click(object sender, EventArgs e)
{
MapWinGIS.Shapefile shpfile;
var opendialog1 = new OpenFileDialog();
int handle;
string ext = “”;
// initialize dialog
opendialog1.Filter = "Supported Formats|*.shp|Shapefile (*.shp)|*.shp";
opendialog1.CheckFileExists = true;
if (opendialog1.ShowDialog(this) == DialogResult.OK)
{
// get the extension of the file
ext = Path.GetExtension(opendialog1.FileName);
if (ext == ".shp")
{
shpfile = new MapWinGIS.ShapefileClass();
// open the shapefile
bool blmCheck = shpfile.Open(opendialog1.FileName);
// add the shapefile to the map
handle = axMap1.AddLayer(shpfile, true);
axMap1.Redraw();
TreeView treeView = new TreeView();
treeView.Dock = DockStyle.Fill;
if (blmCheck)
switch (ClickNum==1)
{
default:
TreeNode node = new TreeNode();
if (node.Nodes.Count > 0)
rootNode.Nodes.Add(node);
//inicio do nó mestre
TreeNode node1 = new TreeNode("Novo Projeto");
TreeNode node2 = new TreeNode(Path.GetFileNameWithoutExtension(shpfile.Filename), new TreeNode[] {node1});
TreeNode node3 = new TreeNode("Editar Linha");
TreeNode node4 = new TreeNode("",new TreeNode[] { node2 } );
TreeNode node5 = new TreeNode("Editar Linha");
TreeNode node6 = new TreeNode("Editar Poligono",new TreeNode[] {node5});
node1.Name = "Child1";
node1.Text = axMap1 = (shpfile.Filename.Categories.Generate(handle, tkClassificationType.ctUniqueValues, 0));
node2.Name = "node1";
node2.Text = (Path.GetFileNameWithoutExtension(shpfile.Filename));
node3.Name = "node2";
node3.Text = "Editar Linha";
node4.Name = "editar";
node4.Text = (Path.GetFileNameWithoutExtension(shpfile.Filename));
node5.Name = "editar";
node5.Text = "Child1";
node6.Name = "editar";
node6.Text = "Parente2";
rootNode.Nodes.AddRange(new TreeNode[] {node4});
this.Controls.Add(rootNode);
// TreeNode a = rootNode.Nodes.Add(Text, "Novo Projeto");
//insere a layer
// TreeNode rootnode = rootNode.Nodes[0].Nodes.Add(Path.GetFileNameWithoutExtension(shpfile.Filename));//meio
//insere a edição da layer
// TreeNode b = rootNode.Nodes[0].Nodes[0].Nodes.Add("Editar");//fim
// node.Nodes.IndexOf(a);// obtem o nó node e retorna ao inicio de [a]
// node.Nodes.IndexOfKey(Path.GetFileNameWithoutExtension(shpfile.Filename));
// node.Nodes.IndexOf(a);
break;
}
treeView.Refresh();//restaura o Treeview
}
}
} />