Click here to Skip to main content
13,197,548 members (45,408 online)
Click here to Skip to main content
Add your own
alternative version


41 bookmarked
Posted 25 Mar 2003

Editable Multi-line ListBox

, 25 Mar 2003
Rate this:
Please Sign up or sign in to vote.
A ListBox control providing multi-line support.

Screenshot of ListBoxXP


If you take a look at the snapshot and run the .exe file you`ll realise that there`s nothing I need to say here. I needed this control with item editing, insertion, deletion, and moving capabilities and I asked, "why not share it with people?"

Using the Code

It`s very easy to use just add a variable based on the class and that`s all. You work with it like a normal listbox.

// powered by
// .............
void CListBoxXP::DrawItem(LPDRAWITEMSTRUCT lpDrawItemStruct) 
    CString szBuf="";
    COLORREF col;
         RECT r;
            HBRUSH br;
            br=::CreateSolidBrush(LightenColor(<BR>                GetSysColor(COLOR_HIGHLIGHT),0.9));
            ::FillRect(lpDrawItemStruct->hDC,<BR>                &lpDrawItemStruct-&gt;rcItem,br);
             FillRect(lpDrawItemStruct-&gt;hDC,<BR>                &lpDrawItemStruct->rcItem,<BR>                (HBRUSH)GetStockObject(WHITE_BRUSH));
         if(lpDrawItemStruct->itemState & ODS_SELECTED)
            HBRUSH br;
            br=::CreateSolidBrush(LightenColor(<BR>                GetSysColor(COLOR_HIGHLIGHT),0.75));
            ::FillRect(lpDrawItemStruct->hDC,<BR>                &lpDrawItemStruct->rcItem,br);
         if(lpDrawItemStruct-&gt;itemState & ODS_FOCUS)
            HBRUSH br;
            br = ::CreateSolidBrush(LightenColor(<BR>                GetSysColor(COLOR_HIGHLIGHT),0.5));
            ::FrameRect(lpDrawItemStruct->hDC,<BR>                &lpDrawItemStruct->rcItem,br);
         if(CountLines(szBuf) > 1)
             DrawText(lpDrawItemStruct->hDC,szBuf,<BR>                strlen(szBuf),&r,<BR>                DT_LEFT|DT_TOP|DT_WORDBREAK);
             DrawText(lpDrawItemStruct->hDC,szBuf,<BR>                strlen(szBuf),&r,<BR>                DT_LEFT|DT_VCENTER|DT_SINGLELINE);

void CListBoxXP::MeasureItem(LPMEASUREITEMSTRUCT lpMeasureItemStruct) 
    HDC hDC;
    char szBuf[512]="";
    ::SendMessage(this->m_hWnd, LB_GETTEXT,<BR>        (WPARAM)lpMeasureItemStruct->itemID,(LPARAM)szBuf);<BR>
    hDC = ::GetDC(this->m_hWnd);
    CRect r;
    ::GetTextMetrics(hDC, &tm);
    ::ReleaseDC(this->m_hWnd, hDC);
// ...<BR>


This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


About the Author

Web Developer
Romania Romania
I have been programming for the past 6 years in VBasic, Delphi, C, C++ .
I also have extended knowledge of webdesign (HTML, CSS, JavaScript, VBScript), webprogramming (PHP, ASP, ASP.NET (C#)) and database integration (mySql, MSSQL Server).
And when I`m not programming I`m working out or working on some personal projects .
Last but not least I`m looking for a project-based job in programming or webdesign .

You may also be interested in...

Comments and Discussions

GeneralGet The edited text in User class Pin
ArtiGujare26-Jan-06 2:25
memberArtiGujare26-Jan-06 2:25 
I am using the editable listboxXP class.
I need to save the changes done to the edit box after user clicks a "save" button.
I am using GetText to retreive the edited data from the list box

CString strRemarks;
mRemarksListBox.GetText(0, strRemarks);
// save remarks

the text still shows the original text and not the updated text. Any idea how to get th edited text in my user class.
Also I have problem with font settings. The text in the editable edit box seems too small. I want to increase the font size.
Please help me.

Thanks and Regards,
Arti Gujare
GeneralIssues with the control with Japanese Windows Pin
cdesylva27-Sep-04 15:57
membercdesylva27-Sep-04 15:57 
GeneralRe: Issues with the control with Japanese Windows Pin
cdesylva27-Sep-04 15:58
membercdesylva27-Sep-04 15:58 
Generalneed help please Pin
Heex8-Jul-04 10:43
sussHeex8-Jul-04 10:43 
GeneralRe: need help please Pin
TomKat8-Jul-04 23:07
memberTomKat8-Jul-04 23:07 
GeneralBug on first addition Pin
Karthik Murugan21-Mar-04 17:15
memberKarthik Murugan21-Mar-04 17:15 
Generalbug! Pin
tang_ghost12-Mar-04 21:44
membertang_ghost12-Mar-04 21:44 
Generalcan't found CNetControl.dsp Pin
tang_ghost12-Mar-04 21:13
membertang_ghost12-Mar-04 21:13 
GeneralRe: can't found CNetControl.dsp Pin
MonirTigerit19-Jul-05 20:48
memberMonirTigerit19-Jul-05 20:48 
Generaldebug assertions Pin
to_be_unknown4-Jun-03 0:41
memberto_be_unknown4-Jun-03 0:41 
QuestionSave and Load data? Pin
chen27-Mar-03 19:42
memberchen27-Mar-03 19:42 
AnswerRe: Save and Load data? Pin
TomKat28-Mar-03 10:17
memberTomKat28-Mar-03 10:17 
GeneralNice! Pin
Ernest Laurentin26-Mar-03 16:52
memberErnest Laurentin26-Mar-03 16:52 
GeneralCool! Pin
Wayzer26-Mar-03 7:01
memberWayzer26-Mar-03 7:01 

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.

Permalink | Advertise | Privacy | Terms of Use | Mobile
Web01 | 2.8.171020.1 | Last Updated 26 Mar 2003
Article Copyright 2003 by TomKat
Everything else Copyright © CodeProject, 1999-2017
Layout: fixed | fluid