Solved

Enable selection of any part of line in CListCtrl

Posted on 1998-07-23
9
375 Views
Last Modified: 2008-03-17
I have created a CListCtrl in a report style with single line selection. I have it sorting by multiple columns and it works great except that users can only click on the text of the first column. If you try to click on any part of the line to the right of the first column, nothing gets selected. This stinks because some of my lists have very small (few characters) first columns. It's natural to think you can click anywhere on the line.

I see that Microsoft Outlook does it right, but I don't see any style settings to control this. Anybody got any ideas on how to enable full line selection in a CListCtrl?
0
Comment
Question by:kmenzel
  • 5
  • 3
9 Comments
 
LVL 2

Accepted Solution

by:
lucidity earned 100 total points
ID: 1168476
OverRide the OnLeftMouseDown function for the control. You should be able to get the logical position of the mouse. Then figure out the distance between the entries in the ListCtrl, with that figure out how far in the list the mouse is and SetCurSel to the entry the mouse is over.
0
 
LVL 11

Expert Comment

by:alexo
ID: 1168477
Actually, there is a much simpler answer.

If you use the new common controls (ver 4.72 is freely available from MS but it is sufficient to have IE >=3 installed) you can use the following:

        ListView_SetExtendedListViewStyle(hListView, LVS_EX_FULLROWSELECT);

Of course, that assumes you have the updated header and library files.  If not, get the Inet SDK (freely available from MS).
0
 
LVL 11

Expert Comment

by:alexo
ID: 1168478
I dunno how this would translate to MFC but MFC questions should not be asked here anyway.  There is an "MFC" topic.
0
 

Author Comment

by:kmenzel
ID: 1168479
That works great and saved me lots of time. Thank you.
0
Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

 
LVL 11

Expert Comment

by:alexo
ID: 1168480
What works great?  Lucidity's answer or my comment?
0
 

Author Comment

by:kmenzel
ID: 1168481
The line
        ListView_SetExtendedListViewStyle(hListView, LVS_EX_FULLROWSELECT);

works great. I did not know that MS had a set of extended styles. I had done many help searchs and looked through 6 books, but did not find this style. But, I sure thought there should be a way to do full row selects. Doesn't make sense not to.

Seems silly that these exetended styles are not incorporated into the regular style base or at least MS should have replaced the older help pages with links to the extended style help pages. I wonder how many other patch type stuff I don't know about because you can't find it unless you already know about it or you use the expert exchange!

Thanks
0
 
LVL 11

Expert Comment

by:alexo
ID: 1168482
>> The line ListView_SetExtendedListViewStyle(...);

So I figured.  Do you realize that you accepted the "OverRide the OnLeftMouseDown" answer instead?  Lucidity got the points because the question was locked by him.


>> Seems silly that these exetended styles are not incorporated into the regular style base

Not silly, just confusing.  You see, they are not really "window styles".  They are flags set and queried by sending appropriate messages to the control (the macro I referred to just does a SendMessage() call).  Therefore you are free to change them at any time, which is not true regarding the "regular style base".

0
 

Author Comment

by:kmenzel
ID: 1168483
No, I did not realize that you did not get the credit. How would I have avoided that. This credit thing is not very straight forward as to how to assign a person credit when a few people have submitted answers. Especially if you don't get a chance to look at an answer until there are multiple answers waiting.

Thanks for clarifing the extended style. Does this mean if my app gets put on a machine without at least ie3.0, the full row select will not work? Even though it was compiled on a machine where it currently works?
0
 
LVL 11

Expert Comment

by:alexo
ID: 1168484
Well, there can only be one pending answer, all the others are considered "comments".  You can "reopen" the question and leave a comment inviting one of those who commented to lock the question instead.

If you'd like to "fix" the situation, you can post a 0-point question in the customer support area (http://www.experts-exchange.com/topics/bin/NewQForm?ta=4) saying that the points for question Q.10066552 should go to <whomever you wish>.

Don't forget to complain LOUDLY that the grading form is very confusing.  It may lead to improvements.

Now, back to the question:

>> the full row select will not work?
Right.  There are ways to overcome it though.

You can test for the installed version of common controls.
    http://www.dejanews.com/getdoc.xp?AN=270672616
    http://www.dejanews.com/getdoc.xp?AN=308663486

You can distribute a new version of common controls with your app.
    http://www.microsoft.com/msdn/downloads/files/40comupd.htm

0

Featured Post

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

What is C++ STL?: STL stands for Standard Template Library and is a part of standard C++ libraries. It contains many useful data structures (containers) and algorithms, which can spare you a lot of the time. Today we will look at the STL Vector. …
  Included as part of the C++ Standard Template Library (STL) is a collection of generic containers. Each of these containers serves a different purpose and has different pros and cons. It is often difficult to decide which container to use and …
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…
The viewer will be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.

706 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

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now