Click here to Skip to main content
Click here to Skip to main content

Store and show Tree struct in a Combobox

By , 31 Jul 2002
 

Sample Image - CWzCombox.gif

Introduction

I am working in a CAPP project which based on database. We often use combo-box to show all table in database to user and let user select a table, it's a simple way, not only for the user but also for coder. In some condition, there is special relationship between one table and another table, the simple combo-box can't describe it. I write a new class to deal with this condition.

I use a struct to store the relationship between items (tables):

typedef struct tagITEMDATA
{
    WORD wParantOriginIdx; //the root item's parent is nRootIndex
    WORD wOriginIdx; //Original index when first insert to listbox
    BYTE cType;
    BYTE cLevel;
}ITEMDATA,*LPITEMDATA;
  • wParantOriginIdx is the item's parent original index (the index when it was first insert to combo-box), the index of items may change when you add or delete items, so we should keep it.
  • wOriginIdx is item's original index.
  • cType mark the item type, maybe use for other special .
  • cLevel is the level of items, children level is higher than parents.

This struct is the core of CWzCombox class, please check source code for detail.

License

This article, along with any associated source code and files, is licensed under The GNU General Public License (GPLv3)

About the Author

Simon.W
Software Developer (Senior)
China China
Member
I had graduated from HuaZhong University of Science & Technology. Now, I'm working in ZTE.

Sign Up to vote   Poor Excellent
Add a reason or comment to your vote: x
Votes of 3 or less require a comment

Comments and Discussions

 
You must Sign In to use this message board.
Search this forum  
    Spacing  Noise  Layout  Per page   
GeneralVery good. One thing to keep in mind thoughmemberstrtdusty7 Mar '05 - 10:38 
Thanks for the quality code!  One thing to keep in mind for those using this.  Because the return index from the AddCTString method is not unique, you need to fill the tree in a depth first fashion (unless I'm missing something).  Indexes within the tree can be duplicated so something like this:
 
	WORD wParentIdx1 = m_comboType.AddCTString(nRootIndex,nTypeTYM,"66kv Concrete Single Pole"); //==0
	WORD wParentlevel1 = m_comboType.AddCTString(wParentIdx1,nTypeTYC,"5/160");//==1
	WORD wParentlevel2 = m_comboType.AddCTString(wParentIdx1,nTypeTYC,"5/180");//==2
	WORD wParentlevel3 = m_comboType.AddCTString(wParentIdx1,nTypeTYC,"5/200");//==3
	WORD wParentlevel4 = m_comboType.AddCTString(wParentIdx1,nTypeTYC,"5/220");//==4
	m_comboType.AddCTString(wParentlevel1,nTypeTYX,"21.5m80kN-C+5/160+G-MS"); //returns an index of 2
	m_comboType.AddCTString(wParentlevel1,nTypeTYX,"21.5m60kN-C+5/160+G-M2"); //returns an index of 3.  But we added it to a parent of 2.  Which one is that?
	m_comboType.AddCTString(wParentlevel1,nTypeTYX,"21.5m24kN-C+5/160+G-M2");//returns an index of 4
	m_comboType.AddCTString(wParentlevel2,nTypeTYX,"21.5m80kN-C+5/180+");//returns an index of 3
	m_comboType.AddCTString(wParentlevel2,nTypeTYX,"21.5m24kN-C+5/180+");//returns an index of 4
	m_comboType.AddCTString(wParentlevel2,nTypeTYX,"21.5m60kN-C+5/180+");//returns an index of 5
 
Will result in some odd results.   
 

However, if you fill the tree depth first, it seems to work great.  I started looking for a non-invasive fix but gave up and just filled the tree the way it expects.

Questionvery nice...one question?membervivadotnet20 Jun '04 - 16:57 
Hello,
very impressive anf thanks for sharing it with us.
I was wondering , is it possible to owner-draw the down-arrow button that drops the list?
 
thanks
vd

GeneralExcellent!memberDominik Reichl2 Jul '03 - 8:55 
Really cool control! Great work!
 
Smile | :)
-Dominik

 

_outp(0x64, 0xAD);
and
__asm mov al, 0xAD __asm out 0x64, al
do the same... but what do they do?? Wink | ;)

GeneralUseful toolmemberDavid Spain6 Aug '02 - 4:12 
Useful general purpose tool, looks like it is well done, and probably many people can use it. Is it ok to remove the bitmap in the center of the dialog?
 
David Spain
GeneralRe: Useful toolmemberXSimon13 Aug '02 - 15:16 

use it freely as your wish!
 

your letter:
Useful general purpose tool, looks like it is well done, and probably many people can use it. Is it ok to remove the bitmap in the center of the dialog?
 
David Spain
 
I am seeking...
For what?
Why did you ask me for what? I don't know!
GeneralPretty Good!!memberWREY5 Aug '02 - 9:07 

Good Job!!
 
Cool | :cool:
 
William

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Permalink | Advertise | Privacy | Mobile
Web03 | 2.6.130523.1 | Last Updated 1 Aug 2002
Article Copyright 2002 by Simon.W
Everything else Copyright © CodeProject, 1999-2013
Terms of Use
Layout: fixed | fluid