Adding Controls To List Control

Implementing Drag And Drop On Tree Items

Many times in the GUI development, we require to insert various other controls inside one control. For example, in a list control, we may have to insert a combo box to allow user to select some options. This sample shows how to go about such problems. Here I am inserting three different controls inside the list control depending on which column user clicks.

If user clicks on the first column a button control will be popped up. User can click on that button to get further functionality. If user clicks on the second column, a edit box is popped up for editing the present text. Similarly, if user hits the third column a combo box will be popped up in its dropdown state so that user can select any option to make the selection for that entry. You can use the similar logic for any other controls to insert inside the list control.

Here simple technique of control subclassing and some CWnd functions like CWnd::Create( ) and CWnd::ShowWindow( ) are used to achieve this. The column on which user has clicked is determined by using CListCtrl::SubItemHitTest( ) function. Then corresponding controls will be created and displayed with specific functionality. Each control has its own class. The main list control is CCoolListCtrl, which is derived from the CListCtrl. The Button control has its functionality wrapped up in the class CCoolButton derived from CButton. The edit control is of class CCoolEdit derived from CEdit. Similarly CCoolCombo from CComboBox for combo box insertion. This provides the programmers a flexibility to add/modify the functionality for each control.

The following figure shows the functionality of this sample.

Download


No comments: