Code implementation in the enumeration array is possible [July 8, 2004 1:57]

zhaozj2021-02-16  61

In the module for data inquiry, think about a problem that is often encountered, it is often adapted to various sort requirements, the general approach is to put a control, such as ComboBox, then write it.

Sort by time

Sort by name

........................

In this way, if there are multiple fields to sort (Eg. Order by uname, tdate), consider multiple, put the controls to be multiple, the code is more cumbersome, how can you make a code can be suitable for all occasions Use? This is used here:

All possible arrangements in the enumeration array.

What is the relationship between this? The idea is like this:

1. Define a number of arrays: It is all a collection that requires the name of the list.

Eg. {"serialno", "ratedate", "cycode"}

2. Enumerate this array, which means this array constitutes a tree, isn't it? And take a look:

Root | - Serialno | | --Ratedate | | | - Cycode // Serialno, Ratedate, Cycode | | | | - Cycode | | --rateDate // Serialno, Cycode, Ratedate | --rateDate | Cycode | | - Serialno // Ratedate, Cycode, Serialno | | | | - Serialno | | - Cycode // Ratedate, Serialno, Cycode | - Cycode | - Serialno | | --rateDate // Cycode, Serialno, ratedate | | --ratedate | - Serialno // Cycode, Ratedate, Serialno

This way, click on one of the nodes, have been getparent, you can find a unique path and do not have node repetition (that is, field pull).

3. When you really use, consider using shortcut menu, you can use a menu node in the above tree, which is that you can only select one of the sequencing paths, such as that you must use order by cycode, rated, SERIALNO, not ORDER BY CYCODE, RATEDATE. Because it is a menu! Only the leaves can click. Luxury, you can use TreeCtrl directly so that each node has a click event, that is, you can select some of them sorted.

The following code is done using TreeCtrl.

#define item_count 5const char item [item_count] [20] = {"AA", "BB", "CC", "DD", "EE"}

// StrPath From the path information of the root node to the parent node, INDEX currently inserted the node index bool isinpath (cstring strpath, int index) {// This function determines if the node to be inserted is in the path ("% s _____% S / N ", strpath.getBuffer (0), & item2 [index]); strpath.releaseBuffer (); int n = strpath.find ((char *) & item2 [index]); if (strpath.find ((char *) ) & item2 [index])> = 0) Return true; Else Return False;} Void TestinSerItem (ctreeCtrl * Treectrl, htreeitym hparent, int from, int count, cstring strpath) {// hparent parent node, from from in array Starting index, count inserts a number (enter next level - 1) // strPath path from = from% item_count; int J = from; for (int i = from; i = item_count) j = 0; isinpath (StrPath, J)) {// Note Do not base J ; j = j% item_count;} htreeItem hcurr; tvinsertstruct TVinsert; tvinsert.hparent = hParent; TVinsert.hinsertafter = NULL; TVINSERT.ITEM.MASK = TVIF_Text; TVinsert.Item.psztext = (char *) & item [j]; hcurr = treectrl-> insertitem (& TVinsert); TestinSerItem (TreeCtrl, Hcurr, i 1, count-1, StrPath (char *) & item [j]);}} Str = "root"; TVinsert.hparent = null; tvinsert.hinsertafter = null; TVIN sert.item.mask = TVIF_TEXT; tvInsert.item.pszText = (LPSTR) str.GetBuffer (0); str.ReleaseBuffer (); // into the parent node HTREEITEM hRoot = treeCtrl.InsertItem (& tvInsert); TestInserItem (& treeCtrl, hRoot , 0, item_count, "");

There is also a similar implementation code http://community.9cbs.net/expert/topic/3157/3157589.xml?temp=.6269342

转载请注明原文地址:https://www.9cbs.com/read-17191.html

New Post(0)