I have the code below to expand the tree node to add childeren to its parents , till the nth level.
Issue : The child is added to the first level always, instead it should have been added till the nth level, to its appropriate parent.
Code below:
public void Populate_Node(Object sender, TreeNodeEventArgs e)
{
// Authenticating
TreeProvider cmsTree = new TreeProvider(MembershipContext.AuthenticatedUser);
//selecting the expanding node
var node = cmsTree.SelectSingleNode(SiteContext.CurrentSiteName, "/Level1-2ndItem", "en-US");
CMS.DocumentEngine.TreeNodeCollection myChildren = node.AllChildren;
//Making array of child treenodes of selected node
IEnumerable<CMS.DocumentEngine.TreeNode> TreeNodes = myChildren.AsEnumerable<CMS.DocumentEngine.TreeNode>();
foreach (var tree in myChildren)
{
System.Web.UI.WebControls.TreeNode ParenTreeNode = new System.Web.UI.WebControls.TreeNode();
ParenTreeNode.Text = tree.NodeID.ToString() + ". " + SiteContext.CurrentSiteName;
ParenTreeNode.Value = tree.NodeID.ToString();
AddExpandedNodes(ParenTreeNode);
}
}
private void AddExpandedNodes(System.Web.UI.WebControls.TreeNode TreeNode)
{
CMS.DocumentEngine.TreeProvider cmsTree = new CMS.DocumentEngine.TreeProvider(CMS.Membership.MembershipContext.AuthenticatedUser);
var node = cmsTree.SelectSingleNode(CMS.SiteProvider.SiteContext.CurrentSiteName, "/", "en-US");
CMS.DocumentEngine.TreeNodeCollection myChildren = node.AllChildren;
IEnumerable<CMS.DocumentEngine.TreeNode> childTreeNodes = myChildren.AsEnumerable<CMS.DocumentEngine.TreeNode>().Where(x => x.NodeParentID == Convert.ToInt32(TreeNode.Value));
foreach (var childTree in childTreeNodes)
{
System.Web.UI.WebControls.TreeNode ChildNode = new System.Web.UI.WebControls.TreeNode();
ChildNode.Text = childTree.NodeID.ToString() + ". " + childTree.DocumentName.ToString();
ChildNode.Value = childTree.NodeID.ToString();
ChildNode.ChildNodes.Add(ChildNode);
AddExpandedNodes(ChildNode);
tvContentTree.Nodes.Add(ChildNode);
}
}
Related
I am using syncfusion's TreeViewAdv in multi column mode.
I am trying to get the selected node's value (from the first column) but I have not been successful.
Has anyone been able to do this?
Many thanks
Edit:
A quick update on how I am populating the control
private void RefreshOptions()
{
List<String> objects = Globals.ThisAddIn.utilities.ListRObjectsWithDetail();
StringBuilder name = new StringBuilder(100);
StringBuilder details = new StringBuilder(200);
Node dataRootNode = new Node();
Node dataParentNode = new Node();
Node dataChildNode1 = new Node();
Node dataChildNode2 = new Node();
Node dataChildNode3 = new Node();
Node functionsRootNode = new Node();
Node functionsParentNode = new Node();
int charLocation;
int indexChild;
int childLevel;
TreeModel _model = new TreeModel();
treeViewAdv1.Model = _model;
treeViewAdv1.BeginUpdate();
dataRootNode = new ColumnNode("Data / Values", "", "");
_model.Nodes.Add(dataRootNode);
functionsRootNode = new ColumnNode("Functions", "", "");
_model.Nodes.Add(functionsRootNode);
foreach (String obj in objects)
{
name.Clear();
details.Clear();
name.Append(obj.Trim());
charLocation = name.ToString().IndexOf(":");
details.Append(name.ToString().Substring(charLocation + 1).Trim());
name.Length = charLocation;
if (details.Length >=10 && details.ToString(0, 10) == "function (")
{
functionsParentNode = new ColumnNode(name.ToString(), "Function", details.ToString());
functionsRootNode.Nodes.Add(functionsParentNode);
}
else
{
indexChild = name.ToString().IndexOf("$");
if (indexChild > -1)
{
childLevel = name.ToString(0, indexChild).Split('.').Length - 1;
name.Remove(0, 1 + childLevel);
switch (indexChild)
{
case 1:
dataChildNode1 = new ColumnNode(name.ToString(), "Data / Value", details.ToString());
dataParentNode.Nodes.Add(dataChildNode1);
break;
case 2:
dataChildNode2 = new ColumnNode(name.ToString(), "Data / Value", details.ToString());
dataChildNode1.Nodes.Add(dataChildNode2);
break;
case 3:
dataChildNode3 = new ColumnNode(name.ToString(), "Data / Value", details.ToString());
dataChildNode2.Nodes.Add(dataChildNode3);
break;
}
}
else
{
dataParentNode = new ColumnNode(name.ToString(), "Data / Value", details.ToString());
dataRootNode.Nodes.Add(dataParentNode);
}
}
}
NodeTextBox ntb = new NodeTextBox();
ntb.DataPropertyName = "Text";
this.treeViewAdv1.NodeControls.Add(ntb);
treeViewAdv1.EndUpdate();
}
I spent some time looking at the TreeViewAdv sample project. Specifically I looked the "FolderBrowser.cs" winform which did have the below NodeMouseDoubleClick event. This correctly wrote the node tot he console.
private void _treeView_NodeMouseDoubleClick(object sender, TreeNodeAdvMouseEventArgs e)
{
Console.WriteLine(e.Node);
}
If I use exactly the same event then my e.Node = "" although my node is fully populated.
I ama getting data from news website with webrequest and show my listview. When user click button , first of all I am getting all news and show my listview, after e.g 15 min user click button again. I am checking my news list if news is exits, I am showing messagebox "There is no fresh news". but if there is a news put all news list in listview again. For example. first lisview count is 75 . and there is 2 fresh news, normally my listview should 77. but listview shows 152. Where is my mistake. can you help me ?
my button click event
private void btnHurriyet_Click(object sender, EventArgs e)
{
Hurriyet hurriyet = new Hurriyet();
List<ListViewItem> list = hurriyet.GetTagsHurriyet();
foreach (var item in list)
{
listView1.Items.Add(item);
}
}
this is my class
public static Dictionary<string, Hurriyet> HurriyetHaberList = new Dictionary<string, Hurriyet>();
public List<ListViewItem> GetTagsHurriyet()
{
XmlDocument xdoc = new XmlDocument();
xdoc.Load("http://www.hurriyet.com.tr/rss/gundem");
XmlElement el = (XmlElement)xdoc.SelectSingleNode("/rss");
if (el != null)
{
el.ParentNode.RemoveChild(el);
}
XmlNode Haberler = el.SelectSingleNode("channel");
List<ListViewItem> listViewItems = new List<ListViewItem>();
bool degismiMi = false;
foreach (XmlNode haber in Haberler.SelectNodes("item"))
{
Hurriyet h = new Hurriyet();
ListViewItem li = new ListViewItem();
//li.Text = haber.SelectSingleNode("title").InnerText;
h.Title = haber.SelectSingleNode("title").InnerText;
if (haber.SelectSingleNode("description").InnerText.Contains(">"))
{
var str1 = haber.SelectSingleNode("description").InnerText.IndexOf(">");
var str2 = haber.SelectSingleNode("description").InnerText.Substring(str1 + 4);
//li.SubItems.Add(str2);
}
else
{
//li.SubItems.Add(haber.SelectSingleNode("description").InnerText);
h.Description = haber.SelectSingleNode("description").InnerText;
}
h.Link = haber.SelectSingleNode("link").InnerText;
//li.SubItems.Add(haber.SelectSingleNode("link").InnerText);
var format = DateTime.Parse(haber.SelectSingleNode("pubDate").InnerText.ToString());
//li.SubItems.Add(format.ToString());
h.PubDate = format;
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(haber.SelectSingleNode("link").InnerText);
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
StreamReader stream = new StreamReader(response.GetResponseStream());
string final_response = stream.ReadToEnd();
string begenningKeyword = "<meta name=\"keywords\" content=\"";
var tags = final_response.IndexOf(begenningKeyword);
var final_response2 = final_response.Substring(tags + begenningKeyword.Length);
var tagsBol = final_response2.IndexOf("\" />");
var lastTags = final_response2.Substring(0, tagsBol);
int yer1;
if (lastTags != string.Empty)
{
h.Tags = lastTags;
//li.SubItems.Add(lastTags);
}
else
{
yer1 = final_response.IndexOf("tagsContainer");
if (yer1 == -1)
{
continue;
}
else
{
yer1 = final_response.IndexOf("tagsContainer");
int yer2 = final_response.IndexOf("</div>", yer1);
var tagDiv = final_response.Substring(yer1, yer2 - yer1);
List<string> listele = new List<string>();
for (int i = 0; i < tagDiv.Length; i++)
{
var firstSpan = tagDiv.IndexOf("<span>");
var firstSpan2 = tagDiv.IndexOf("<span itemprop=\"keywords\">");
if (firstSpan != -1)
{
var secondSpan = tagDiv.IndexOf("</a>", firstSpan);
var lastSpan = tagDiv.Substring(firstSpan, secondSpan - firstSpan);
var remo = lastSpan.Replace("<span>", "");
var remo2 = remo.Replace("</span>", "");
listele.Add(remo2);
tagDiv = tagDiv.Replace(lastSpan, "");
}
else if (firstSpan2 != -1)
{
var secondSpan = tagDiv.IndexOf("</a>", firstSpan2);
var lastSpan = tagDiv.Substring(firstSpan2, secondSpan - firstSpan2);
var remo = lastSpan.Replace("<span itemprop=\"keywords\">", "");
var remo2 = remo.Replace("</span>", "");
listele.Add(remo2);
tagDiv = tagDiv.Replace(lastSpan, "");
}
else
break;
}
string c = string.Empty;
foreach (var item in listele)
{
c += item + ",";
}
//li.SubItems.Add(c.Substring(0, c.Length - 1));
h.Tags = c.Substring(0, c.Length - 1);
}
}
if (HurriyetHaberList.ContainsKey(haber.SelectSingleNode("link").InnerText) == false)
{
HurriyetHaberList.Add(haber.SelectSingleNode("link").InnerText, h);
degismiMi = true;
//listViewItems.Insert(0,li);
}
}
if (!degismiMi)
{
MessageBox.Show("Haberlerde değişiklik olmadı");
}
else
{
listViewItems.Clear();
foreach (var item in HurriyetHaberList.OrderByDescending(x => x.Value.PubDate).ToList())
{
ListViewItem lstItem = new ListViewItem();
lstItem.Text = item.Value.Title;
lstItem.SubItems.Add(item.Value.Description);
lstItem.SubItems.Add(item.Value.Link);
lstItem.SubItems.Add(item.Value.PubDate.ToString());
lstItem.SubItems.Add(item.Value.Tags);
listViewItems.Add(lstItem);
}
}
return listViewItems;
}
Screenshot
The problem is that your code
hurriyet.GetTagsHurriyet();
Delivers all 77 Items and this result is than added to your list Control with the below code
foreach (var item in list)
{
listView1.Items.Add(item);
}
You need to clear your listView1 or make sure that the method GetTagsHurriyet() only returns new items.
So either do the following:
private void btnHurriyet_Click(object sender, EventArgs e)
{
Hurriyet hurriyet = new Hurriyet();
List<ListViewItem> list = hurriyet.GetTagsHurriyet();
listView1.Items.Clear(); //<-- added line
foreach (var item in list)
{
listView1.Items.Add(item);
}
}
Or in your GetTagsHurriyet() method only fill the list if your dictionary says it is new:
if (HurriyetHaberList.ContainsKey(haber.SelectSingleNode("link").InnerText) == false)
{
HurriyetHaberList.Add(haber.SelectSingleNode("link").InnerText, h);
degismiMi = true;
//listViewItems.Insert(0,li);
//add items to listViewItems here and drop the code below
}
Edit:
Based on the comment below:
Something like this:
(Didnt test the code, removed some comments to make it smaller also changed some stuff here and there)
private void btnHurriyet_Click(object sender, EventArgs e)
{
Hurriyet hurriyet = new Hurriyet();
List<ListViewItem> list = hurriyet.GetTagsHurriyet();
if (!list.Any())
MessageBox.Show("Haberlerde değişiklik olmadı");
else
{
foreach (var item in list)
listView1.Items.Add(item);
}
}
public static Dictionary<string, Hurriyet> HurriyetHaberList = new Dictionary<string, Hurriyet>();
public List<ListViewItem> GetTagsHurriyet()
{
XmlDocument xdoc = new XmlDocument();
xdoc.Load("http://www.hurriyet.com.tr/rss/gundem");
XmlElement el = (XmlElement)xdoc.SelectSingleNode("/rss");
if (el != null)
el.ParentNode.RemoveChild(el);
XmlNode Haberler = el.SelectSingleNode("channel");
List<Hurriyet> newHurriyets = new List<Hurriyet>();
bool degismiMi = false;
foreach (XmlNode haber in Haberler.SelectNodes("item"))
{
var link = haber.SelectSingleNode("link").InnerText;
if (HurriyetHaberList.ContainsKey(link))
continue;
Hurriyet h = new Hurriyet();
h.Title = haber.SelectSingleNode("title").InnerText;
if (!haber.SelectSingleNode("description").InnerText.Contains(">"))
h.Description = haber.SelectSingleNode("description").InnerText;
h.Link = link;
var format = DateTime.Parse(haber.SelectSingleNode("pubDate").InnerText.ToString());
h.PubDate = format;
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(link);
using (HttpWebResponse response = (HttpWebResponse)request.GetResponse())
using (StreamReader stream = new StreamReader(response.GetResponseStream()))
{
string final_response = stream.ReadToEnd();
string begenningKeyword = "<meta name=\"keywords\" content=\"";
var tags = final_response.IndexOf(begenningKeyword);
var final_response2 = final_response.Substring(tags + begenningKeyword.Length);
var tagsBol = final_response2.IndexOf("\" />");
var lastTags = final_response2.Substring(0, tagsBol);
int yer1;
if (!string.IsNullOrEmpty(lastTags))
h.Tags = lastTags;
else
{
yer1 = final_response.IndexOf("tagsContainer");
if (yer1 == -1)
continue;
yer1 = final_response.IndexOf("tagsContainer");
int yer2 = final_response.IndexOf("</div>", yer1);
var tagDiv = final_response.Substring(yer1, yer2 - yer1);
List<string> listele = new List<string>();
for (int i = 0; i < tagDiv.Length; i++)
{
var firstSpan = tagDiv.IndexOf("<span>");
var firstSpan2 = tagDiv.IndexOf("<span itemprop=\"keywords\">");
if (firstSpan != -1)
{
var secondSpan = tagDiv.IndexOf("</a>", firstSpan);
var lastSpan = tagDiv.Substring(firstSpan, secondSpan - firstSpan);
var remo = lastSpan.Replace("<span>", "");
var remo2 = remo.Replace("</span>", "");
listele.Add(remo2);
tagDiv = tagDiv.Replace(lastSpan, "");
}
else if (firstSpan2 != -1)
{
var secondSpan = tagDiv.IndexOf("</a>", firstSpan2);
var lastSpan = tagDiv.Substring(firstSpan2, secondSpan - firstSpan2);
var remo = lastSpan.Replace("<span itemprop=\"keywords\">", "");
var remo2 = remo.Replace("</span>", "");
listele.Add(remo2);
tagDiv = tagDiv.Replace(lastSpan, "");
}
else
break;
}
h.Tags = string.Join(",", listele);
}
}
HurriyetHaberList.Add(link, h);
newHurriyets.Add(h);
}
List<ListViewItem> listViewItems = new List<ListViewItem>();
foreach (var item in newHurriyets.OrderByDescending(x => x.PubDate))
{
ListViewItem lstItem = new ListViewItem();
lstItem.Text = item.Title;
lstItem.SubItems.Add(item.Description);
lstItem.SubItems.Add(item.Link);
lstItem.SubItems.Add(item.PubDate.ToString());
lstItem.SubItems.Add(item.Tags);
listViewItems.Add(lstItem);
}
return listViewItems;
}
You can clear items before filling:
private void btnHurriyet_Click(object sender, EventArgs e)
{
Hurriyet hurriyet = new Hurriyet();
List<ListViewItem> list = hurriyet.GetTagsHurriyet();
listView1.Items.Clear(); // Clear items
foreach (var item in list)
{
listView1.Items.Add(item);
}
}
otherwise you would have to check if listView1 does not have item you want to add (not by reference, maybe some property?). This case however will not handle deleting items
private void btnHurriyet_Click(object sender, EventArgs e)
{
Hurriyet hurriyet = new Hurriyet();
List<ListViewItem> list = hurriyet.GetTagsHurriyet();
foreach (var item in list)
{
if(!IsItemPresent(item)) // You should implement this method somehow
listView1.Items.Add(item);
}
}
listView1 should clear before u add new items. becose their was old data.
put this code listView1.Clear(); before start loop.
listView1.Clear();
private void btnHurriyet_Click(object sender, EventArgs e)
{
Hurriyet hurriyet = new Hurriyet();
List<ListViewItem> list = hurriyet.GetTagsHurriyet();
listView1.Clear();
foreach (var item in list)
{
listView1.Items.Add(item);
}
}
I have a table in this structure
ListA labelName
1 Colorado
1 Wyoming
1 Illinois
2 New York
2 Ohio
I am trying to create a tree where if LISTA = 1, it goes under one node called "header one" and Colorado, Wyoming, Illinois as its Leaf and samething with value "2"... by doing this I am getting 3 "Header one" nodes instead of having all those three nodes under one...
SqlCommand cmd = con.CreateCommand();
comd.CommandText = "SELECT * FROM myTable";
con.Open();
SqlDataReader reader = comd.ExecuteReader();
while (reader.Read())
{
City MyData = new City();
MyData.ListA = reader["ListA"].ToString().Trim();
MyData.labelName = reader["labelName"].ToString().Trim();
giveData.Add(MyData);
}
int count = 1;
List<TreeNode> myNode = new List<TreeNode>();
foreach (City MyData in giveData)
{
// 1st foreach
if (MyData.ListA != "1")
{
TreeNode treeNode = new TreeNode();
treeNode.id = count++;
treeNode.name = "Header One";
treeNode.leaf = false;
List<TreeNode> Level1 = new List<TreeNode>();
foreach (City labelName in giveData)
{
if (labelName.ListA == "1")
{// 2nd foreach
TreeNode node1 = new TreeNode();
node1.id = count++;
node1.name = labelName.labelName;
node1.leaf = true;
Level1.Add(node1);
}
}
treeNode.children = Level1;
myNode.Add(treeNode);
}
else if (MyData.ListA != "2")
{
TreeNode treeNode = new TreeNode();
treeNode.id = count++;
treeNode.name = "Header Two";
treeNode.leaf = false;
List<TreeNode> Level1 = new List<TreeNode>();
foreach (City labelName in giveData)
{
if (labelName.ListA == "2")
{// 2nd foreach
TreeNode node1 = new TreeNode();
node1.id = count++;
node1.name = labelName.labelName;
node1.leaf = true;
Level1.Add(node1);
}
}
treeNode.children = Level1;
myNode.Add(treeNode);
}
}
return JsonConvert.SerializeObject(myNode);
What would be the best way to handle this
What you need to do is group the data on ListA.
var groups = giveData.GroupBy(state => state.ListA);
foreach(var group in groups)
{
//add header to treeview
string header = group.Key;
foreach(var state in group)
{
//add this state as a child of the group you just added
}
}
I'd also suggest creating a lookup to help you map the ListA number to it's textual representation:
var headerLookup = new Dictionary<string, string>()
{
{"1", "Header One"},
{"2", "Header Two"},
{"3", "Header Three"}
};
This will allow you to do the following:
string headerText = headerLookup[group.Key];
I need to create a valid jqTree JSON structure from Active Directory OUs. I'm testing with a recursive method (InfoNode) for this, but I can not get it.
The resulting json goes into the string json. The first node to process is the DirectoryEntry parent with the default domain root. The recursive method (InfoNode) gets
the current child node, filter by "OU" and creates the JSON properties "label" and "path". Before checks whether this node has more children to write the end of the current JSON item. Finally, if there are more children, run the method (InfoNode) again:
public static DirectoryEntry root = new DirectoryEntry("LDAP://RootDSE");
public string dom = (string)root.Properties["defaultNamingContext"].Value;
public string json = "";
public Form1()
{
InitializeComponent();
DirectoryEntry parent = new DirectoryEntry("LDAP://" + dom);
InfoNode(parent);
System.IO.File.WriteAllText(#"json.txt", json);
}
void InfoNode(DirectoryEntry node)
{
string[] arr = node.Name.Split('=');
if (arr[0] == "OU")
{
json += "'children':[{'label':'" + arr[1] + "','path':'" + node.Path + "'";
if (nodo.Children == null)
{
json += "}]";
}
else
{
json += ",";
}
}
if (node.Children != null)
{
foreach (DirectoryEntry child in node.Children)
{
InfoNode(child);
}
}
}
You should provide more detail on what fails with your code.
I'll give a try :-)
You may try to modify your code like below.
Not optimal (using startswith before splitting, more string.Format , testing children with startswith before calling the method recursively, would be better), but I guess it should work.
Maybe you will need to load the children from the ldap source as you progress in the tree.
public string json = "";
public Form1()
{
InitializeComponent();
DirectoryEntry parent = new DirectoryEntry("LDAP://" + dom);
json = InfoNode(parent);
System.IO.File.WriteAllText(#"json.txt", json);
}
public string InfoNode(DirectoryEntry node)
{
string[] arr = node.Name.Split('=');
var result = string.Empty;
if (arr[0].Equals("ou",StringComparison.InvariantCultureIgnoreCase))
{
result = "'{'label':'" + arr[1] + "','path':'" + node.Path + "'";
if (node.Children.Cast<DirectoryEntry>().Any())
{
result += String.Format(", children:[{0}]",
String.Join(",\n ",
node.Children.Cast<DirectoryEntry>()
.Select(InfoNode).Where(s=>!string.IsNullOrEmpty(s))
.ToArray()));
}
result += "}";
}
return result;
}
I have to develop a web part for SharePoint that reads a list and creates a tree view.
The tree view has to be organized as follows:
The root (or roots) is to be created by a choice field which represents a category, for instance Drinks,
the child nodes are the name of the rows that contain that category, the tree view has to be created programmatically.
List:
Title(string) Category(Choice)
Coke Drinks
Beer Drinks
Fish Food
Chips Food
Would produce this:
Drinks
Coke
Beer
Food
Fish
Chips
code I have so far
TreeView treeView;
TreeNode rootNode;
TreeNode childNode;
protected override void RenderContents(System.Web.UI.HtmlTextWriter writer)
{
// render the control
base.RenderContents(writer);
}
protected override void CreateChildControls()
{
List<TreeNode> items = new List<TreeNode>();
base.CreateChildControls();
// get the current site
using (SPSite Site = new SPSite(SPContext.Current.Site.Url + "/UberWiki"))
{
using (SPWeb currentWeb = Site.OpenWeb())
{
// set the tree view properties
SPList list = currentWeb.Lists["Pages"];
SPFieldChoice field = (SPFieldChoice)list.Fields["Categories"];
foreach (string str in field.Choices)
{
treeView = new System.Web.UI.WebControls.TreeView();
rootNode = new System.Web.UI.WebControls.TreeNode(str);
treeView.Nodes.Add(rootNode);
foreach (SPListItem rows in list.Items)
{
childNode = new System.Web.UI.WebControls.TreeNode(rows.Title);
treeView.Nodes.Add(childNode);
}
}
}
this.Controls.Add(treeView);
base.CreateChildControls();
}
}
Found the solution:
using (SPSite Site = new SPSite(SPContext.Current.Site.Url + "/UberWiki"))
{
using (SPWeb currentWeb = Site.OpenWeb())
{
SPList list = currentWeb.Lists["Pages"];
SPFieldChoice field = (SPFieldChoice)list.Fields["Categories"];
treeView = new System.Web.UI.WebControls.TreeView();
foreach (string str in field.Choices)
{
treeNode = new System.Web.UI.WebControls.TreeNode(str);
foreach (SPListItem rows in list.Items)
{
SPFieldMultiChoiceValue multiChoice = new SPFieldMultiChoiceValue(Convert.ToString(rows["Wiki Categories"]));
string input = multiChoice.ToString();
//remove the ;# that comes with the multiple choiches
string cleanString = input.Replace(";#", "");
if (cleanString == str)
{
string PageNameWithExt = rows.Name;
childNode = new System.Web.UI.WebControls.TreeNode(PageNameWithExt);
treeNode.ChildNodes.Add(childNode);
}
}
treeView.Nodes.Add(treeNode);
}
}
}
this.Controls.Add(treeView);
base.CreateChildControls();
}
Another solution without the need to clean the multi choice string values
using (SPSite Site = new SPSite(SPContext.Current.Site.Url + "/UberWiki"))
{
using (SPWeb currentWeb = Site.OpenWeb())
{
// set the tree view properties
SPList list = currentWeb.GetList(currentWeb.Url+"/Lists/Pages");
SPFieldChoice field = (SPFieldChoice)list.Fields["Categories"];
treeView = new System.Web.UI.WebControls.TreeView();
// Add root nodes
foreach (string str in field.Choices)
{
rootNode = new System.Web.UI.WebControls.TreeNode(str);
treeView.Nodes.Add(rootNode);
}
// Add child nodes
foreach (SPListItem rows in list.Items)
{
childNode = new System.Web.UI.WebControls.TreeNode(rows["Title"].ToString());
treeView.FindNode(rows["Categories"].ToString()).ChildNodes.Add(childNode);
}
}
this.Controls.Add(treeView);
base.CreateChildControls();
}