Expression >
Forums Home
>
Related Technologies Forums
>
Windows Presentation Foundation (WPF)
>
having troubles inserting a new node in a treeview
having troubles inserting a new node in a treeview
- I have a program that has a feature to add a node in a treeview, if the treeview item that will hold the new node has no childs a new List<TreeViewItem> with the new node is asigned to the ItemsSource property, the new node is displayed but the expand simbol (+) in the treeviewitem where the new node was added is not shown.
¿Any ideas?
Greetings.
All Replies
List<TreeViewItem> should be of type ObservableCollection for VisualTree to listen to its change. But...
You should not add TreeViewItems to TreeView or TreeViewControls. Conceptually, these are meant to display hierarchichal data so you should add child node object to parent node object.
Bigsby, Lisboa, Portugal
O que for, quando for, é que será o que é...
Wenn ist das Nunstruck git und Slotermeyer? Ja! ... Beiherhund das Oder die Flipperwaldt gersput!
http://bigsby.eu- Hi Carlos,
I can not understand why "+" symbol is not expected to be shown when it has multiple child elments, would you please clarify?
Best regards,
Bruce Zhou
Please remember to mark the replies as answers if they help and unmark them if they provide no help.
Welcome to the All-In-One Code Framework! If you have any feedback, please tell us. - Imagine i have something like:
my screen shows the "myTreeViewItem" and "myChilds" contents but theres no "expantion + sign" in the left side of the "myTreeViewitem" tvi...if(myTreeViewItem.ItemsSource ==null) { List<TreeViewItem> myChilds = new List<TreeViewItem>(); myChilds.Add(theNewNode; myTreeViewItem.ItemsSource =myChilds; }
- Hi,
Can you post the full code.
Thank You
Please mark posts as answers/helpful if it answers your query. This would be helpful for others facing the same kind of problem private void MueveNodo(List<TreeViewItem> itemSelecPadre) { if (itemSelecPadre.Count > 1) { List<TreeViewItem> hijos = (List<TreeViewItem>)itemSelecPadre[1].ItemsSource; hijos.Remove(itemSelecPadre[0]); itemSelecPadre[1].Items.Refresh(); } else { List<TreeViewItem> hijos = (List<TreeViewItem>)Ventana.treeView.ItemsSource; hijos.Remove(itemSelecPadre[0]); Ventana.treeView.Items.Refresh(); } if (target.ItemsSource != null) { List<TreeViewItem> hijos = (List<TreeViewItem>)target.ItemsSource; hijos.Add(itemSelecPadre[0]); target.IsExpanded = true; target.Items.Refresh(); } else { List<TreeViewItem> hijos = new List<TreeViewItem>(); target.ItemsSource = hijos; hijos.Add(itemSelecPadre[0]); target.IsExpanded = true; } IFachadaTesauro fac = new FachadaTesauro(); TemaTO padre = (TemaTO)target.Tag; TemaTO hijo = (TemaTO)itemSelecPadre[0].Tag; hijo.IDPadre = padre.IDTema; int error = fac.actualizaPadre(hijo); if (hijo.Materia != padre.Materia) { error = fac.actualizaMateria(hijo.IDTema, padre.Materia); } Ventana.treeView.UpdateLayout(); }The specific part where the trouble is is on theif (target.ItemsSource != null)
block.
Hi
Here, i am sending the example of code test it ur side. it's working my side perfectly
http://www.sendspace.com/file/g0pzws

