trouble in inserting data to tree control
-
Hi..I want to insert a item to an existing tree and I want to make the item become the child of one of the tree members for example: before: root ..|_parent1 ..|_parent2 ..|_parent3 after: root ..|_parent1 ..|_parent2 ......|_(I want to insert my new item in here) ..|_parent3 but I didn't know how to do it. Plz help me because I'm a newbie in MFC programming thx.
-
Hi..I want to insert a item to an existing tree and I want to make the item become the child of one of the tree members for example: before: root ..|_parent1 ..|_parent2 ..|_parent3 after: root ..|_parent1 ..|_parent2 ......|_(I want to insert my new item in here) ..|_parent3 but I didn't know how to do it. Plz help me because I'm a newbie in MFC programming thx.
m_treeCtrl.InsertItem. From MSDN: HTREEITEM InsertItem( LPTVINSERTSTRUCT lpInsertStruct ); HTREEITEM InsertItem(UINT nMask, LPCTSTR lpszItem, int nImage, int nSelectedImage, UINT nState, UINT nStateMask, LPARAM lParam, HTREEITEM hParent, HTREEITEM hInsertAfter ); Download this project[^], you'll find it usefull. Marc Soleda. ... she said you are the perfect stranger she said baby let's keep it like this... Tunnel of Love, Dire Straits.
-
Hi..I want to insert a item to an existing tree and I want to make the item become the child of one of the tree members for example: before: root ..|_parent1 ..|_parent2 ..|_parent3 after: root ..|_parent1 ..|_parent2 ......|_(I want to insert my new item in here) ..|_parent3 but I didn't know how to do it. Plz help me because I'm a newbie in MFC programming thx.
Call
CTreeCtrl::GetItem()
on the "parent2" item. Then callCTreeCtrl::InsertItem()
to insert the new "child" item below that.
"Ideas are a dime a dozen. People who put them into action are priceless." - Unknown
-
Call
CTreeCtrl::GetItem()
on the "parent2" item. Then callCTreeCtrl::InsertItem()
to insert the new "child" item below that.
"Ideas are a dime a dozen. People who put them into action are priceless." - Unknown
thx 2 you all for your help. Can a tree control access another atttributes of a data? I am planning to make a tree control from a list of data for example, I am a list of datas, each of data consists of Name, adrress, phone number, etc and I want to make the tree control based on the name. Does it exist any command to access/ display other attributes by clicking the tree element? thx..
-
thx 2 you all for your help. Can a tree control access another atttributes of a data? I am planning to make a tree control from a list of data for example, I am a list of datas, each of data consists of Name, adrress, phone number, etc and I want to make the tree control based on the name. Does it exist any command to access/ display other attributes by clicking the tree element? thx..
After inserting a node in the tree control, use
SetItemData()
to associate that node with the item in the list.
"Ideas are a dime a dozen. People who put them into action are priceless." - Unknown
-
After inserting a node in the tree control, use
SetItemData()
to associate that node with the item in the list.
"Ideas are a dime a dozen. People who put them into action are priceless." - Unknown
Can u give me some examples pls?because I'm still new in MFC and lack of experience in programming. thx
-
Can u give me some examples pls?because I'm still new in MFC and lack of experience in programming. thx
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vclib/html/_mfc_ctreectrl.3a3a.setitemdata.asp[^] In your case, the second parameter to
SetItemData()
would be an item in your data structure.
"Ideas are a dime a dozen. People who put them into action are priceless." - Unknown
-
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vclib/html/_mfc_ctreectrl.3a3a.setitemdata.asp[^] In your case, the second parameter to
SetItemData()
would be an item in your data structure.
"Ideas are a dime a dozen. People who put them into action are priceless." - Unknown
thx...I have read the link u gave me, but I think it is not what I' looking for for example I have a data base file that consist name,age,address,phone number,etc and I want to make a tree control based on the name for example. And then if I click the tree control attributes, I can access the other database attributes such as the age,address,phone,etc. Is there any function or maybe some links to help me..because I'm so confused. thx...
-
thx...I have read the link u gave me, but I think it is not what I' looking for for example I have a data base file that consist name,age,address,phone number,etc and I want to make a tree control based on the name for example. And then if I click the tree control attributes, I can access the other database attributes such as the age,address,phone,etc. Is there any function or maybe some links to help me..because I'm so confused. thx...
One way would be to read the records from the database into a data structure and populate the tree control from that data structure.
"Ideas are a dime a dozen. People who put them into action are priceless." - Unknown
-
One way would be to read the records from the database into a data structure and populate the tree control from that data structure.
"Ideas are a dime a dozen. People who put them into action are priceless." - Unknown
thx...I also have some problem on populating the tree control. I want to group the tree attributes if there are same occurences. I have tried to make the function, but when I run it, my program become not responding. here is my function: HTREEITEM CCDBMainDlg::LoadTree(CStringArray& tree) { m_hItem = m_treeCDB.GetNextItem(m_hItem,TVGN_ROOT); if(m_treeCDB.ItemHasChildren(m_hItem)) { m_hItem = m_treeCDB.GetChildItem(m_hItem); while(m_treeCDB.GetItemText(m_hItem).Compare(tree.GetAt(12))!=NULL || m_hItem != NULL) { m_hItem = m_treeCDB.GetNextSiblingItem(m_hItem); } if(m_treeCDB.ItemHasChildren(m_hItem)) { m_hItem = m_treeCDB.GetChildItem(m_hItem); while(m_treeCDB.GetItemText(m_hItem).Compare(tree.GetAt(11))!=NULL || m_hItem != NULL) { m_hItem = m_treeCDB.GetNextSiblingItem(m_hItem); } if(m_treeCDB.ItemHasChildren(m_hItem)) { m_hItem = m_treeCDB.GetChildItem(m_hItem); while(m_treeCDB.GetItemText(m_hItem).Compare(tree.GetAt(0))!=NULL || m_hItem != NULL) { m_hItem = m_treeCDB.GetNextSiblingItem(m_hItem); } } else { m_hItem = m_treeCDB.InsertItem(tree.GetAt(0),0,1,m_hItem); } } else { m_hItem = m_treeCDB.InsertItem(tree.GetAt(11),0,1,m_hItem); m_hItem = m_treeCDB.InsertItem(tree.GetAt(0),0,1,m_hItem); } } else { m_hItem = m_treeCDB.InsertItem(tree.GetAt(12),0,1,m_hItem); m_hItem = m_treeCDB.InsertItem(tree.GetAt(11),0,1,m_hItem); m_hItem = m_treeCDB.InsertItem(tree.GetAt(0),0,1,m_hItem); } m_hItem = m_treeCDB.InsertItem(tree.GetAt(1),0,1,m_hItem); m_treeCDB.EnsureVisible(m_hItem); return m_hItem; } pls help. thx.
-
thx...I also have some problem on populating the tree control. I want to group the tree attributes if there are same occurences. I have tried to make the function, but when I run it, my program become not responding. here is my function: HTREEITEM CCDBMainDlg::LoadTree(CStringArray& tree) { m_hItem = m_treeCDB.GetNextItem(m_hItem,TVGN_ROOT); if(m_treeCDB.ItemHasChildren(m_hItem)) { m_hItem = m_treeCDB.GetChildItem(m_hItem); while(m_treeCDB.GetItemText(m_hItem).Compare(tree.GetAt(12))!=NULL || m_hItem != NULL) { m_hItem = m_treeCDB.GetNextSiblingItem(m_hItem); } if(m_treeCDB.ItemHasChildren(m_hItem)) { m_hItem = m_treeCDB.GetChildItem(m_hItem); while(m_treeCDB.GetItemText(m_hItem).Compare(tree.GetAt(11))!=NULL || m_hItem != NULL) { m_hItem = m_treeCDB.GetNextSiblingItem(m_hItem); } if(m_treeCDB.ItemHasChildren(m_hItem)) { m_hItem = m_treeCDB.GetChildItem(m_hItem); while(m_treeCDB.GetItemText(m_hItem).Compare(tree.GetAt(0))!=NULL || m_hItem != NULL) { m_hItem = m_treeCDB.GetNextSiblingItem(m_hItem); } } else { m_hItem = m_treeCDB.InsertItem(tree.GetAt(0),0,1,m_hItem); } } else { m_hItem = m_treeCDB.InsertItem(tree.GetAt(11),0,1,m_hItem); m_hItem = m_treeCDB.InsertItem(tree.GetAt(0),0,1,m_hItem); } } else { m_hItem = m_treeCDB.InsertItem(tree.GetAt(12),0,1,m_hItem); m_hItem = m_treeCDB.InsertItem(tree.GetAt(11),0,1,m_hItem); m_hItem = m_treeCDB.InsertItem(tree.GetAt(0),0,1,m_hItem); } m_hItem = m_treeCDB.InsertItem(tree.GetAt(1),0,1,m_hItem); m_treeCDB.EnsureVisible(m_hItem); return m_hItem; } pls help. thx.
firebolt77 wrote: ...but when I run it, my program become not responding. One of the
while
loops is not ending. You'll need to set a breakpoint on each one, run the program using F5, and note which breakpoint was not hit. That'll tell you which loop is faulty.
"Ideas are a dime a dozen. People who put them into action are priceless." - Unknown