Is there a way to automatically adjust a list column in MFC?
The program I'm editing uses this code to generate the columns in a listbox:
m_list.InsertCol开发者_如何学JAVAumn(0,_T("Parameter"), LVCFMT_LEFT, 90);
m_list.InsertColumn(1,_T("Show?"), LVCFMT_LEFT, 50);
m_list.InsertColumn(2,_T("Value"), LVCFMT_LEFT, 400);
When the user is using the program, the user can click on a row (cell? I'm not sure of the nomenclature) and enter some text. The problem is it will only allow the user to enter as much text as the column is wide. So in this case the user clicks a cell in the "Value" column (which is 400 pixels wide) and it will only allow the user to enter 74 characters.
Is there a way to make it so that the user can enter as many characters as they like, but have it truncate the displayed text to the column width (similar to the way Windows truncates long filenames)? The values also get stored in a data structure somewhere else inside the program.
This is extracted from MSDN here
To customize label editing, implement a handler for LVN_BEGINLABELEDIT and have it send an LVM_GETEDITCONTROL message to the list-view control. If a label is being edited, the return value will be a handle to the edit control. Use this handle to customize the edit control by sending the usual EM_XXX messages
Update:
As an example, this is a typical scenario:
- Subclass CListCtrl. This will be the class from which you instantiate
m_list
- In your CListCtrl subclass override
OnBeginLabelEdit()
- In your
OnBeginLabelEdit()
callSendMessage(LVM_GETEDITCONTROL)
which returnsHWND
to the Edit control for editing text - Given the Edit control window handle, do what ever you want with it: moving, resizing, or even subclassing.
精彩评论