
Introduction
Because the CListCtrl
class can't show different row heights, I created this derived class to simulate big strings in multilines. After inserting a multiline string into a list cell, the CListCtrl
class shows strange symbols to represent endlines ('\r\n'
). This project draws a tiny key symbol [+] before a big string, allowing the user to expand or contract the row with a double-click.
How this Class Works
This project is ready to replace CListCtrl
when you need to present a multiline string. It draws its own gridlines, so you shouldn't use the LVS_EX_GRIDLINES
extended style. Use the ShowGrid(bool)
function to show/hide gridlines and the ShowMinimized(bool)
function to show/hide the whole string in the row when minimized. The code redraws all list items, drawing key symbols [+] before a big string. When it finds a big string, the class saves the number of lines with SetItemData
. After the user clicks twice over the row, the class inserts more rows below to represent the whole string. It then redraws the list to simulate a unique row. Clicking again, the class deletes extra lines, minimizing the row.
Using the Code
- Insert the MultiLineListCtrl.h and MultiLineListCtrl.cpp files into your project.
- Create a list control.
- Set the
view
property of your list to report
.
- Create a
CListCtrl
member variable in your class.
- Insert the following code:
#insert "MultiLineListCtrl.h"
- Replace your
CListCtrl
member variable with a CMultiLineListCtrl
member variable.
Cautions
This project is as simple as possible. It changes the number of rows and uses the item data. Close all rows, i.e. use CloseAll()
, before working with its cells or overwriting its basic functions.
History