Here is a better explanation of what I need it, I think is done most of the part but I just cant figure it out on ViewMode. Please if someone can help me, thanks!
I have a List of KeyWords (overview) and I want to Edit/Insert and View the information related to an specific KeyWord or insert a new one. On this details keyword page for insert, edit and view, I have to show a treeview, with categories and themes, parent node are categories and childs themes. The user can check any of these themes (treeview based on checkboxes) to relate the selected keyword with those themes. For example for the category Science I have themes Mathematics, Physics, Geography, if I want the keyword Geometry, I could check on the treeview Mathematics. On view mode, I just need to show the selected themes and category parent, but for the insert and edit has to show all and also the themes are checked.
I have this entities and navigation properties and an data example:
Entity Option(OptionId, ParentId, Description, virtual navigation property KeyWordOptions) KeyWordOption(OptionId, KeywordID, virtual navigation property Option)
Option Entity
OptionId ParentID Description
1 0 Informatics
2 1 Development
3 0 Architecture
4 1 Systems
5 1 Hardware
6 3 Civil Engineering
7 1 Software
KeyWordOption Entity
OptionId KeywordID ID KeywordDescription
1 8 8 Visual Studio
2 8 2 Autocad
4 2 5 Monitor
5 5 9 Eclipse
2 9
7 8
7 2
7 9
Result Would be for Eclipse keyword(id = 9) at EditMode:
Informatics
Development (checked)
System
Hardware
Software (checked)
Architecture
Civil Engineering
Result Would be for Eclipse keyword(id = 9) at ViewMode:
Informatics
Development (checked)
Software (checked)
My code is:
BindTreeView(OptionList, null);
private void BindTreeView(IEnumerable<Opcion> OptionList, TreeNode parentNode)
{
var nodes = OptionList.Where(x => parentNode == null ? x.ParentID == 0 : x.ParentID == int.Parse(parentNode.Value));
if (mode != FormViewMode.View)
{
foreach (var node in nodes)
{
TreeNode newNode = new TreeNode();
newNode.Text = node.Description.ToString();
newNode.Value = node.OptionID.ToString();
if (parentNode == null)
{
TreeViewOptions.Nodes.Add(newNode);
}
else
{
if (node.KeyWordOptions.Where(c => c.KeywordID == _idKeyWord).Count() > 0)
{
newNode.Checked = true;
parentNode.Expand();
}
parentNode.ChildNodes.Add(newNode);
}
BindTreeView(OptionList, newNode);
}
}
else
{
foreach (var node in nodes)
{
TreeNode newNode = new TreeNode();
newNode.Text = node.Descripcion.ToString();
newNode.Value = node.OpcionID.ToString();
if (parentNode == null && node.KeyWordOptions.Where(c => c.KeywordID == _idKeyWord).Count() > 0)
{
TreeViewOptions.Nodes.Add(newNode);
}
else
{
if (node.KeyWordOptions.Where(c => c.KeywordID == _idKeyWord).Count() > 0)
{
newNode.Checked = true;
parentNode.Expand();
}
parentNode.ChildNodes.Add(newNode);
}
BindTreeView(OptionList, newNode);
}
}
}
}
I dont know what I have to do to exclude the Nodes
that don't match the KeywordId