Click here to Skip to main content
15,867,308 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 134.1K   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

 
GeneralPretty Good!! Pin
WREY5-Aug-02 9:07
WREY5-Aug-02 9:07 
Good Job!!

Cool | :cool:

William

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.