?
Solved

CListCtrl

Posted on 1999-01-17
14
Medium Priority
?
835 Views
Last Modified: 2013-11-20
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.
0
Comment
Question by:RMD010799
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 7
  • 5
  • 2
14 Comments
 
LVL 6

Expert Comment

by:snoegler
ID: 1327800
See www.codeguru.com / head for "listview control" - "class with
full row highlighting, dragable headers, sorting".

I think this should help you :)

0
 
LVL 8

Expert Comment

by:Answers2000
ID: 1327801
Assuming m_list is the CListCtrl object you want this for, do :-

ListView_SetExtendedListViewStyle( m_list.m_hWnd, LVS_EX_FULLROWSELECT ) ;

0
 

Author Comment

by:RMD010799
ID: 1327802
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_SetExtendedListViewStyle(mylistctrl.m_hWnd, LVS_EX_FULLROWSELECT);

And it didn't seem to have any effect.
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
LVL 8

Expert Comment

by:Answers2000
ID: 1327803
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!
0
 

Author Comment

by:RMD010799
ID: 1327804
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...
0
 
LVL 8

Accepted Solution

by:
Answers2000 earned 200 total points
ID: 1327805
1. InsertColumn

m_list.InsertColumn( col, str,                  LVCFMT_LEFT, nWidth ) ;

col = 0 in your case
str = the column heading text (pointer to a string or CString)
nWidth = width of column

2. You can calculate the width required by getting the window size for the control

CRect rect ;
m_list.GetWindow( &rect ) ;
int nWidth = rect.Width() ;

Actually you may want to make the column width less than the width of the list box (by the size of the vertical scroll bar).  As the V-scroll is displayed if the list contains enough items to scroll, to do this

nWidth -= ::GetSystemMetrics( SM_CXVSCROLL ) ;

3. You don't select columns, you select items (which corresponds to _whole_ rows_).  So there is no code req'd for this.

If you want to select an item (row), use

m_list.SetItemState( nIndex, LVIS_SELECTED, LVIS_SELECTED ) ;

where nIndex gives the index of the item


OKAY NOW ?



0
 

Author Comment

by:RMD010799
ID: 1327806
Thanks!
0
 

Author Comment

by:RMD010799
ID: 1327807
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_CXVSCROLL);

pListCtrl->SetExtendedStyle(LVS_REPORT | 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?
0
 

Author Comment

by:RMD010799
ID: 1327808
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_CXVSCROLL);

pListCtrl->SetExtendedStyle(LVS_REPORT | 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?
0
 
LVL 8

Expert Comment

by:Answers2000
ID: 1327809
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!
0
 
LVL 8

Expert Comment

by:Answers2000
ID: 1327810
SetExtendedStyle is not a VC5 function (at least not in the help) - but I assume this is okay

I think we're there now ?
0
 

Author Comment

by:RMD010799
ID: 1327811
Nope. I added

pContactListCtrl->SetColumnWidth(0, nWidth);

and the nWidth is up in the 300s... so that's not the problem.

What else could be the problem???
0
 

Author Comment

by:RMD010799
ID: 1327812
Oh... and I do have VC6.
0
 
LVL 6

Expert Comment

by:snoegler
ID: 1327813
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 ...
0

Featured Post

Will your db performance match your db growth?

In Percona’s white paper “Performance at Scale: Keeping Your Database on Its Toes,” we take a high-level approach to what you need to think about when planning for database scalability.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In this article, I'll describe -- and show pictures of -- some of the significant additions that have been made available to programmers in the MFC Feature Pack for Visual C++ 2008.  These same feature are in the MFC libraries that come with Visual …
Introduction: Ownerdraw of the grid button.  A singleton class implentation and usage. Continuing from the fifth article about sudoku.   Open the project in visual studio. Go to the class view – CGridButton should be visible as a class.  R…
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…
Suggested Courses
Course of the Month15 days, 14 hours left to enroll

741 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question