i have any issuses with my treeview. a customer needs to add a root folder to his file manager. I tried using a treeview to populate the tree from his database. this is a part of his database:
db example fields
This is my c# code:
private void PopulateTreeView()
{
int idPortafoglioValue = 0;
if (Request.QueryString["id"] != null)
idPortafoglioValue = int.Parse(Request.QueryString["id"]);
string strsql = "SELECT DISTINCT cartella FROM TblPortafogli_Documenti WHERE idportafoglio =" + idPortafoglioValue + creaWhere(); ;
DataTable dt = Funzioni.OttieniTabellaDalDataBase(strsql);
List<string> cartelleCreate = new List<string>();
TreeView.Nodes.Clear(); // Clear existing nodes
// Crea il nodo radice
TreeNode rootNode = new TreeNode("Root");
TreeView.Nodes.Add(rootNode);
if (dt.Rows.Count == 0)
{
TreeNode rootNode = new TreeNode("Root");
TreeView.Nodes.Add(rootNode);
return;
}
else
{
foreach (DataRow dr in dt.Rows)
{
string cartella = dr["cartella"].ToString();
string dir = "";
if (cartella.Contains("/"))
cartella = cartella.Replace('/', '\');
if (cartella.StartsWith("Root\") == false && cartella != "Root")
cartella = "Root\" + cartella;
foreach (string stringa in cartella.Split('\'))
{
if (dir == "")
{
dir = stringa;
if (!cartelleCreate.Contains(dir))
{
rootNode.ChildNodes.Add(new TreeNode(dir, dir));
cartelleCreate.Add(dir);
}
}
else
{
string nodoPadre = dir;
dir += "\" + stringa;
if (!cartelleCreate.Contains(dir))
{
TreeNode nodo = new TreeNode();
trovaNodo(nodoPadre, rootNode.ChildNodes, ref nodo);
nodo.ChildNodes.Add(new TreeNode(stringa, dir));
cartelleCreate.Add(dir);
}
}
}
}
}
TreeView.CollapseAll();
}
public void trovaNodo(string value, TreeNodeCollection nodi, ref TreeNode node)
{
TreeNode t = new TreeNode();
foreach (TreeNode nodo in nodi)
{
if (nodo.Value == value)
{
node = nodo;
return;
}
trovaNodo(value, nodo.ChildNodes, ref node);
}
return;
}
i can’t edit the path column in his database, because it’s a 80gb database..
i tried to add this line, but there are always new issues: (for example: saving a path like Rootexample i get a RootRootExample folder..
if (cartella.StartsWith("Root\") == false && cartella != "Root")
cartella = "Root\" + cartella;
can you help me? any suggestion?
Regards
Zakkwylde84 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.