Click here to Skip to main content
15,860,844 members
Articles / Desktop Programming / MFC
Article

Store and show Tree struct in a Combobox

Rate me:
Please Sign up or sign in to vote.
4.52/5 (15 votes)
31 Jul 2002GPL3 133.9K   4.1K   49   16
Store and show Tree struct in Combobox

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)


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

Comments and Discussions

 
PraiseThanks a lot Pin
Member 1618306915-Jan-24 14:54
Member 1618306915-Jan-24 14:54 
GeneralVery useful code ! Pin
Nice Gom18-Jan-11 13:31
Nice Gom18-Jan-11 13:31 
GeneralImplementation in C/C++ using the Win32 API Pin
hcraes4-Nov-09 7:16
hcraes4-Nov-09 7:16 
GeneralSame thing in C# Pin
rixwan29-Jan-09 0:48
rixwan29-Jan-09 0:48 
QuestionItem Data Pin
blackbondi7-Jan-08 2:18
blackbondi7-Jan-08 2:18 
AnswerRe: Item Data Pin
Apollo_Apollo18-Jun-08 16:50
Apollo_Apollo18-Jun-08 16:50 
General1 question Pin
VC Spark20-Jun-07 1:06
VC Spark20-Jun-07 1:06 
GeneralRe: 1 question Pin
Simon.W26-Jun-07 4:32
Simon.W26-Jun-07 4:32 
GeneralRe: 1 question Pin
VC Spark4-Jul-07 3:04
VC Spark4-Jul-07 3:04 
GeneralThank you Pin
johnxie28-Sep-06 20:06
johnxie28-Sep-06 20:06 
GeneralVery good. One thing to keep in mind though Pin
strtdusty7-Mar-05 10:38
strtdusty7-Mar-05 10:38 
Questionvery nice...one question? Pin
vivadot20-Jun-04 16:57
vivadot20-Jun-04 16:57 
GeneralExcellent! Pin
Dominik Reichl2-Jul-03 8:55
Dominik Reichl2-Jul-03 8:55 
GeneralUseful tool Pin
David Spain6-Aug-02 4:12
David Spain6-Aug-02 4:12 
GeneralRe: Useful tool Pin
Simon.W13-Aug-02 15:16
Simon.W13-Aug-02 15:16 
GeneralPretty Good!! Pin
WREY5-Aug-02 9:07
WREY5-Aug-02 9:07 

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

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.