Enable selection of any part of line in CListCtrl

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?
kmenzelAsked:
Who is Participating?
 
lucidityCommented:
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
 
alexoCommented:
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
 
alexoCommented:
I dunno how this would translate to MFC but MFC questions should not be asked here anyway.  There is an "MFC" topic.
0
Cloud Class® Course: SQL Server Core 2016

This course will introduce you to SQL Server Core 2016, as well as teach you about SSMS, data tools, installation, server configuration, using Management Studio, and writing and executing queries.

 
kmenzelAuthor Commented:
That works great and saved me lots of time. Thank you.
0
 
alexoCommented:
What works great?  Lucidity's answer or my comment?
0
 
kmenzelAuthor Commented:
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
 
alexoCommented:
>> 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
 
kmenzelAuthor Commented:
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
 
alexoCommented:
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
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.