RMD010799
asked on
CListCtrl
I am using a CListCtrl in my program. It is in small icon mode, but I can use list mode too. I just want a single column of items. When an item is selected, it only selects the contents of the string that comprises that item. It also won't select an item if the user clicks to the right of the text in that row. How would I make it so that when a user clicks on that item (or anywhere in that row), the entire row is selected? Basically... I want the apperence that ICQ has. When a user clicks anywhere in the row of a contact, the entire row is selected. Help is much appreciated.
Assuming m_list is the CListCtrl object you want this for, do :-
ListView_SetExtendedListVi ewStyle( m_list.m_hWnd, LVS_EX_FULLROWSELECT ) ;
ListView_SetExtendedListVi
ASKER
I added your code (Answer2000), and it compiled fine. But I still have the exact same result. Only the text iself is highlighted. Again, my list box is of type CListCtrl. I have it set to small icon mode. I did not derive a class from it... simple declared it like:
CListCtrl mylistctrl;
I changed it to the small icon mode in the resource editor. And then I call your function:
ListView_SetExtendedListVi ewStyle(my listctrl.m _hWnd, LVS_EX_FULLROWSELECT);
And it didn't seem to have any effect.
CListCtrl mylistctrl;
I changed it to the small icon mode in the resource editor. And then I call your function:
ListView_SetExtendedListVi
And it didn't seem to have any effect.
You need to use the details mode (instead of small icon) - this is LVS_REPORT instead of LVS_SMALLICON
When you use details mode, you can have only column (or more if you like), but you must create it using InsertColumn, and probably want to set the column width of this one column using SetColumnWidth.
The reason that the full row select option doesn't work in small icon mode, is that the layout of icons isn't necessary underneath each other (the user can layout the icons in different ways).
When in the LVS_REPORT style, you can turn of the column header by also using the LVS_NOCOLUMNHEADER style if you want.
I hope this makes more sense now!
When you use details mode, you can have only column (or more if you like), but you must create it using InsertColumn, and probably want to set the column width of this one column using SetColumnWidth.
The reason that the full row select option doesn't work in small icon mode, is that the layout of icons isn't necessary underneath each other (the user can layout the icons in different ways).
When in the LVS_REPORT style, you can turn of the column header by also using the LVS_NOCOLUMNHEADER style if you want.
I hope this makes more sense now!
ASKER
Ok... we are almost there. ;-) I am trying to insert a column like you suggested... but am getting nothing. I get a grey blank header, and the items that should have been added, aren't there. Could you provied code that shows how to insert a column, set it so that it is the width of the entire control (so it fills up the list box...) and makes it so that the entire column is selected when it's clicked? Thanks...
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks!
ASKER
Damnit... I tried it and same deal. I used the following code, and all I get is a grey header row, and none of my list items. The header shouln't be there, and it's not adding my list items.
CRect rect;
int nWidth;
pListCtrl->GetWindowRect(& rect);
nWidth = rect.Width();
nWidth -= ::GetSystemMetrics(SM_CXVS CROLL);
pListCtrl->SetExtendedStyl e(LVS_REPO RT | LVS_NOCOLUMNHEADER);
pListCtrl->InsertColumn(0, "Test", LVCFMT_LEFT, nWidth);
// Contacts is an array of items to be inserted into my list.
for(int j = 0; j < Contacts.GetSize(); j++)
{
pListCtrl->InsertItem(j, Contacts.GetAt(j).sNick);
}
What gives?
CRect rect;
int nWidth;
pListCtrl->GetWindowRect(&
nWidth = rect.Width();
nWidth -= ::GetSystemMetrics(SM_CXVS
pListCtrl->SetExtendedStyl
pListCtrl->InsertColumn(0,
// Contacts is an array of items to be inserted into my list.
for(int j = 0; j < Contacts.GetSize(); j++)
{
pListCtrl->InsertItem(j, Contacts.GetAt(j).sNick);
}
What gives?
ASKER
Damnit... I tried it and same deal. I used the following code, and all I get is a grey header row, and none of my list items. The header shouln't be there, and it's not adding my list items.
CRect rect;
int nWidth;
pListCtrl->GetWindowRect(& rect);
nWidth = rect.Width();
nWidth -= ::GetSystemMetrics(SM_CXVS CROLL);
pListCtrl->SetExtendedStyl e(LVS_REPO RT | LVS_NOCOLUMNHEADER);
pListCtrl->InsertColumn(0, "Test", LVCFMT_LEFT, nWidth);
// Contacts is an array of items to be inserted into my list.
for(int j = 0; j < Contacts.GetSize(); j++)
{
pListCtrl->InsertItem(j, Contacts.GetAt(j).sNick);
}
What gives?
CRect rect;
int nWidth;
pListCtrl->GetWindowRect(&
nWidth = rect.Width();
nWidth -= ::GetSystemMetrics(SM_CXVS
pListCtrl->SetExtendedStyl
pListCtrl->InsertColumn(0,
// Contacts is an array of items to be inserted into my list.
for(int j = 0; j < Contacts.GetSize(); j++)
{
pListCtrl->InsertItem(j, Contacts.GetAt(j).sNick);
}
What gives?
pListCtrl->InsertColumn(0, "Test", LVCFMT_LEFT, nWidth);
ASSERT( nWidth > 0 ) ; // just a double check for me !
pListCtrl->SetColumnWidth( 0, nWidth ) ; // <--- you missed this line out!
ASSERT( nWidth > 0 ) ; // just a double check for me !
pListCtrl->SetColumnWidth(
SetExtendedStyle is not a VC5 function (at least not in the help) - but I assume this is okay
I think we're there now ?
I think we're there now ?
ASKER
Nope. I added
pContactListCtrl->SetColum nWidth(0, nWidth);
and the nWidth is up in the 300s... so that's not the problem.
What else could be the problem???
pContactListCtrl->SetColum
and the nWidth is up in the 300s... so that's not the problem.
What else could be the problem???
ASKER
Oh... and I do have VC6.
Why don't you try the classes from codeguru?
They also provide some extra functionality, like dragable headers
and automated sorting. It's worth a look ...
They also provide some extra functionality, like dragable headers
and automated sorting. It's worth a look ...
full row highlighting, dragable headers, sorting".
I think this should help you :)