Hi and thanks for reading.
As with most things in VC++ (as it seems to me), something simple takes forever to figure out. Here's the deal. I have a list control with 3 columns. I want to size the columns based on the total width of the list control and not on hard-coded values. Here's my code:
As with most things in VC++ (as it seems to me), something simple takes forever to figure out. Here's the deal. I have a list control with 3 columns. I want to size the columns based on the total width of the list control and not on hard-coded values. Here's my code:
Code:
CRect rListViewWidth;
LV_COLUMN listColumn;
int nColumn = 0;
char* arColumns[3] = {"One", "Two", "Three"};
// Set up the list control.
listColumn.mask = LVCF_FMT|LVCF_WIDTH|LVCF_TEXT|LVCF_SUBITEM;
listColumn.fmt = LVCFMT_LEFT;
::SendMessage(m_listCtrl.m_hWnd, LVM_SETEXTENDEDLISTVIEWSTYLE,
LVS_EX_FULLROWSELECT, LVS_EX_FULLROWSELECT);
m_listCtrl.GetWindowRect(&rListViewWidth);
int nWidth = rListViewWidth.Width();
// Add the column headers to the list view.
for( nColumn = 0; nColumn < 3; nColumn++ )
{
listColumn.iSubItem = nColumn;
listColumn.pszText = arColumns[nColumn];
// Size the columns.
if(nColumn == 0) // One
listColumn.cx = (nWidth * 20 / 100);
else if(nColumn == 1) // Two
listColumn.cx = (nWidth * 37 / 100);
else if(nColumn == 2) // Three
listColumn.cx = (nWidth * 42 / 100);
m_listCtrl.InsertColumn(nColumn, &listColumn);
}[code]
I put in the (nWidth * x / 100) to avoid compiler warnings about converting from double to int. Anyway, I know this is simple, but I've already spent too much time trying to figure it out. Can someone tell me how to do this?
Thanks,
OneSource