Width of listview columns not respected
I have a listview where I add several columns:
LVCOLUMN column;
column.mask = LVCF_FMT | LVCF_TEXT | LVCF_WIDTH | LVCF_SUBITEM | LVCF_IDEALWIDTH;
column.fmt = LVCFMT_LEFT;
for(size_t i = 0; i < columns.size(); ++i)
{
const string columnName = Format("{0}. {1} ({2})", i + 1, columns[i].Name.empty() ? "?" : columns[i].Name, boost::to_lower_copy(columns[i].GetTypeName()));
column.iSubItem = i;
column.pszText = (char *)columnName.c_str();
column.cchTextMax = columnName.length();
column.cx = column.cxIdeal = (columns[i].Type == COLUMN_TYPE_STRING) ? 130 : 100;
ListView_InsertColumn(mListView, i, &column);
++mColumnCount;
}
Notice in parti开发者_如何学运维cular column.cx = column.cxIdeal = (columns[i].Type == COLUMN_TYPE_STRING) ? 130 : 100;
.
This is not respected; this is how the listview looks like:
It's also worth mentioning that without targeting Windows Common Controls 6.0 in the manifest file the code works perfectly and the columns have the correct width.
EDIT: Setting cxMin to the width works, but then I can't manually resize the columns so that they have less width (at runtime).
Vista and up has auto-sizing for columns for version 6. Its exact behavior isn't documented well. Either drop LVCF_IDEALWIDTH or use LVCF_MINWIDTH and set the cxMin member.
精彩评论