Click here to Skip to main content
Click here to Skip to main content
Go to top

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

, 29 Dec 2003
Rate this:
Please Sign up or sign in to vote.
List control that supports in place combo box and edit control within the cells as well as read only columns

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)

Share

About the Author

The.Saint
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

 
GeneralRe: Missing type-specifier : opertor = Pinmemberhauke0914-Oct-06 21:37 
GeneralRe: Missing type-specifier : opertor = Pinmembervalenfour23-Apr-09 1:14 
GeneralRe: Missing type-specifier : opertor = PinmemberKhaluaf M. Latypov29-Oct-12 7:52 
QuestionIs it possible to generate 2 CComboListCtrl in a form? Pinmemberdstosch22-Aug-06 3:12 
How I can generate 2 CComboListCtrl in a form?
I found no way.
Questionhow about combo box inside of dropdown list PinmemberHuang Runlei12-Mar-06 15:06 
AnswerRe: how about combo box inside of dropdown list PinmemberThe.Saint30-Mar-06 17:45 
QuestionHelp me! How to initialize the combobox? Pinmemberrslonghorn27-Feb-06 15:35 
AnswerRe: Help me! How to initialize the combobox? PinmemberThe.Saint30-Mar-06 17:44 
GeneralJump to next field Pinmemberespene3-Feb-06 10:00 
GeneralDisplay issue if list is scrolled while editing field PinmemberGray197122-Dec-05 6:31 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Mobile
Web03 | 2.8.140926.1 | Last Updated 30 Dec 2003
Article Copyright 2003 by The.Saint
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid