In the interface interface, you can often see interrelated pull-up boxes. For example, when the query condition is a class application, when setting the query condition, it is often the first drop-down box that includes items to be queried. One item is selected, and the options in the second drop-down box becomes the operator corresponding to the project type. The selection in the third drop-down box becomes an optional value corresponding to the item. Generally, this relationship is in a container window such as a dialog box where the drop-down box control is located. By the first drop-down SELECTCHANGE notification message, according to the selected item, the rear correlation pull-down box is processed. In this way, the relationship between the drop-down box control is placed in the container class to handle, the code of the container class is more chaotic; and these pull-down boxes are basically lost. Based on the above analysis, I wrote some drop-down boxes, put the interactions between the drop-down box control into their own class, in the container class, only responsible for assigning the data source of the drop-down box. And process the relationship between them. The specific code is about the following:
Typedef Map
// Observer drop-down box class cobcombobox: public ccomboBox {ob_map m_mapcontent; // data source void update (String strkey); // Update according to the type selected by the topic, traversing the MAP inside, finds a match, call Refreshcontent Regeneration Drop-down option Void AddDataSource (CSTRING STRKEY, CSTRINGARRITEMCONTENT); // External Setting Data Source in Void Refreshcontent (List
// drop-down box theme class CSubComboBox: public CComboBox {list
Details, here is not described here, nothing more than some operations between STL and CString / CStringArray
When using external use, you can write a function similar to the following: void cxxxdlg :: INitCombo (void) {// assigns a drop-down option for the first drop-down box, 1 and Hello, type INT and String MFC_SUB_MAP MAPCONTENT; MAPContent. Setat (_T ("1"), _t ("int")); mapContent.Setat (_t ("hello"), _t ("string")); m_cbbtype.adddataource (mapContent);
// Give the second drop-down box, that is, the operator pulls the frame data source CStringArray Arrintop, arrstringop; arritocop.add (_t ("==")); arritop.add (_t ("! ="));
Arrstringop.Add (_T ("null")); arrstringop.add (_t ("contain")); arrstringop.add (_t ("nonContain));
// int type operator is == and! = M_cbboperator.addDataSourceItem (_T ("int"), arritient); // String type operator as null, contain, and noncontain m_cbbotater.adddataSource (_T ("string") arrstringop);
// Give the third drop-down box, that is, the optional value drop-down frame data source CStringArray Arrint, Arrstring; Arrint.Add (_T ("2")); arrit .add (_T ("3")); arrit. Add (_T ("4")); arrint.add (_t ("5")); arrit .add (_t ("6"));
Arrstring.add (_T ("a")); arrstring.add (_t ("b")); arrstring.add (_t ("c")); arrstring.add (_t ("d")); arrstring. Add (_T ("e"));
// int type optional value is 2, 3, 4, 5, 6 m_cbbbvalue.adddataSourceItem (_t ("int"), arrint); // String type optional value is A, B, C, D, E M_cbbvalue.adddataSourceItem (_T ("String"), arrstring;
// Finally define the observation relationship m_cbbtype.addobserver (& m_cbootor); m_cbbtype.addobserver (& m_cbbvalue);}
Thus, when the first drop-down box selection 1 or Hello, the latter two pull-up box will display the corresponding operator and optional value according to the selection. Moreover, in the master dialog CXXXDLG, as long as the data source and the relationship can be defined, it is clear.