Click here to Skip to main content
15,880,503 members
Articles / Desktop Programming / MFC

Customized Report List Control With In Place Combo Box & Edit Control

Rate me:
Please Sign up or sign in to vote.
4.57/5 (27 votes)
29 Dec 2003CPOL4 min read 256.9K   9K   64   60
List control that supports in place combo box and edit control within the cells as well as read only columns

Image 1

Introduction

List control especially with the “report” style is one of the most commonly used controls in any UI.

At times as a developer, we would like to be able to

  • Select from a list of items for the value of a cell
  • Key in the value for any of the cells
  • Entire read only column

Developing a list control with these features takes substantial amount of time. I have just tried to create reusable classes that would provide the developer to accommodate in place drop down combo box and edit control.

The columns of the list control can be assigned the above mentioned properties through the public interfaces. This sample is also an example of a control embedded within another control by making the embedded control an attribute of the parent control. By default all the cells support in place edit control.

The code for this article was written on Windows 2000 Professional with Microsoft Visual C++ 6. I have tested the and used the same in my work.

Features

The developer who needs to use a list control as described above just has to include the following files in the project

  • ComboListCtrl.cpp
  • ComboListCtrl.h
  • InPlaceEdit.cpp
  • InPlaceEdit.h
  • InPlaceCombo.cpp
  • InPlaceCombo.h

The developer will need to create a list control resource and associate a control member variable with the same. Then type “CListCtrl” will have to be modified to “CComboListCtrl”.

The columns that need to support in place combo box, edit control and read only property can be specified using the public interfaces available.

The list of items to be shown in the drop down of the combo box can be specified by the parent class. This allows different columns to have different set of items.

In case of the edit control, the valid characters can be specified. If nothing is specified then all characters are considered valid. In addition to the internal validations for characters being keyed in and pasted, the parent control is given a notification for further validations. This allows the parent class to handle any validation specific to the format.

The read only columns as the name suggests is beyond the end user manipulation.

The developer can also enable or disable the horizontal and vertical scroll bars for the in place combo box.

Public Methods

The columns which need to support the in place combo box can be set by passing the column index to SetComboColumns. By default this function will enable the support of combo box in the cells. The combo box support can be reset by passing the second default argument as false.

// Sets/Resets the column, which support the in place combo box 
void SetComboColumns(int iColumnIndex, bool bSet = true); 

The columns which need to act as read only can be set by passing the column index to SetReadOnlyColumns. By default this function will enable the read only property in the cells. The combo box support can be reset by passing the second default argument as false.

// Sets/Resets the column, which support the in place edit control 
void SetReadOnlyColumns(int iColumnIndex, bool bSet = true); 

The valid characters for the edit control can be set by SetValidEditCtrlCharacters. The in place edit control will allow only these characters to be keyed in or pasted to the control. On pasting either all invalid characters or a combination of valid and invalid characters, the paste operation will not succeed.

// Sets the valid characters for the edit ctrl 
void SetValidEditCtrlCharacters(CString& rstrValidCharacters); 

The combo box usually has the ability to support vertical and horizontal scroll bars. But in case of an embedded in place control the need for the same would depend on the usage. The scroll bars can be enabled or disabled by the following interfaces which function much similar to the EnableWindow().

// Enables the vertical scroll if the bool passed is true 
// Disables the vertical scroll if the bool passed is false 
// The default value for the argument is true 
void EnableVScroll(bool bEnable = true); 

// Enables the horizontal scroll if the bool passed is true 
// Disables the horizontal scroll if the bool passed is false 
// The default value for the argument is true 
void EnableHScroll(bool bEnable = true);

User Defined Messages

The text entered in the edit control may need to be validated for its format as per the usage. For this the in place control will have to send a message to the parent of the list control indicating that end of edit operation. The user defined message WM_VALIDATE is used sent to the parent to indicate the end of editing. The parent class may handle this message to make the necessary validations for the format.

// This message is posted to the parent 
// The message can be handled to make the necessary validations, if any 
#define WM_VALIDATE WM_USER + 0x7FFD 

The items in the combo box will have to be externally specified by the parent of the list control. The WM_SET_ITEMS message is posted using ::SendMessage() to the parent. The parent can handle this message and fill in the list of items to be shown in the combo box. The items can be different for each column. This can be achieved as shown in the example below.

// This message is posted to the parent
// The message should be handled to specify the items 
// to the added to the combo
#define WM_SET_ITEMS WM_USER + 0x7FFC

Example

LRESULT CMyDialog::PopulateComboList(WPARAM wParam, LPARAM lParam)
{ 
    CStringList* pComboList = reinterpret_cast<CSTRINGLIST*> (lParam);
    pComboList->RemoveAll(); 
    if (iColumnIndex == 1)
    {  pComboList->AddTail("Name1"); 
       pComboList->AddTail("Name2");pComboList->AddTail("Name3");
    }
    else if (iColumnIndex == 2)
        {pComboList->AddTail("Age1"); 
         pComboList->AddTail("Age2");pComboList->AddTail("Age3");
    }
} 

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Web Developer
Japan Japan
The Saint is a software professional having worked extensively on UI development on VC++ in the intial years.

He currently works as a System Analyst catering to project development & management. He loves to explore & improve his all round knowledge & technical skills.

He is addicted to playing computer games, loves to travel & listen to music.

Comments and Discussions

 
GeneralMy vote of 5 Pin
Anton9627-Oct-22 5:57
Anton9627-Oct-22 5:57 
GeneralMy vote of 5 Pin
Member 109321248-Jul-14 0:58
Member 109321248-Jul-14 0:58 
QuestionHow to get Combo selection? Pin
Member 100657957-Apr-14 8:22
Member 100657957-Apr-14 8:22 
QuestionTrying to make work for VS2008 CPropertyPage - having issues Pin
Member 100657957-Apr-14 7:50
Member 100657957-Apr-14 7:50 
GeneralMy vote of 5 Pin
mnem9-Dec-10 5:01
mnem9-Dec-10 5:01 
GeneralText of one editable column is automattically set on another editable column. Pin
Le@rner8-Dec-10 23:37
Le@rner8-Dec-10 23:37 
GeneralBug on InPlaceEdit Pin
tddtddtdd30-Mar-09 17:43
tddtddtdd30-Mar-09 17:43 
GeneralRe: Bug on InPlaceEdit Pin
Ogi18-Jun-09 7:39
Ogi18-Jun-09 7:39 
Would you please post an example how to fix this bug or at least tell us which function generates these two LButton events.
GeneralCant't Use In VS2008 Pin
dericwen4-Mar-09 15:49
dericwen4-Mar-09 15:49 
QuestionDrawing a Frame around the EditControl in the Listbox Pin
BStramke6-May-08 20:09
BStramke6-May-08 20:09 
GeneralError for On_paste Pin
storeytime26-Mar-07 11:49
storeytime26-Mar-07 11:49 
GeneralRe: Error for On_paste Pin
storeytime26-Mar-07 11:53
storeytime26-Mar-07 11:53 
GeneralEditable combo box Pin
Aryan S26-Mar-07 0:41
Aryan S26-Mar-07 0:41 
GeneralProblem in 'OnGetdispinfo' with dialog box on XP Pin
Elaaber9-Mar-07 21:44
Elaaber9-Mar-07 21:44 
QuestionHow to resize combo box to fit into CListCtrl ????/// Pin
ranu_hai6-Nov-06 0:39
ranu_hai6-Nov-06 0:39 
GeneralMissing type-specifier : opertor = Pin
hauke0911-Oct-06 0:36
hauke0911-Oct-06 0:36 
GeneralRe: Missing type-specifier : opertor = Pin
The.Saint11-Oct-06 14:46
The.Saint11-Oct-06 14:46 
GeneralRe: Missing type-specifier : opertor = Pin
hauke0914-Oct-06 21:37
hauke0914-Oct-06 21:37 
GeneralRe: Missing type-specifier : opertor = Pin
csystemsaz23-Apr-09 1:14
csystemsaz23-Apr-09 1:14 
GeneralRe: Missing type-specifier : opertor = Pin
Khaluaf M. Latypov29-Oct-12 7:52
Khaluaf M. Latypov29-Oct-12 7:52 
QuestionIs it possible to generate 2 CComboListCtrl in a form? Pin
dstosch22-Aug-06 3:12
dstosch22-Aug-06 3:12 
Questionhow about combo box inside of dropdown list Pin
Huang Runlei12-Mar-06 15:06
Huang Runlei12-Mar-06 15:06 
AnswerRe: how about combo box inside of dropdown list Pin
The.Saint30-Mar-06 17:45
The.Saint30-Mar-06 17:45 
QuestionHelp me! How to initialize the combobox? Pin
rslonghorn27-Feb-06 15:35
rslonghorn27-Feb-06 15:35 
AnswerRe: Help me! How to initialize the combobox? Pin
The.Saint30-Mar-06 17:44
The.Saint30-Mar-06 17:44 

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.