Solved

Sorting Header of a listview!!!

Posted on 2000-02-25
7
585 Views
Last Modified: 2013-11-20
Hi,

The initial property of my listview is no sorting header.

Now, I want to change this style after inserting some data into the lisrview.
Thus, I try to modify the style of the listview in order to let the user to sort each column by clicking the header but it is not success.

--------------------------------------------------------------------------
DWORD ListStyle=LVS_REPORT|LVS_EDITLABELS|LVS_SORTASCENDING;
int modify = m_list1.ModifyStyle(LVS_NOSORTHEADER,ListStyle,SWP_SHOWWINDOW);

TRACE("modify result = %d\n", modify);
--------------------------------------------------------------------------

I found the value of modify is equal to 1.
What mistake had I made?

Thanks

0
Comment
Question by:ee_lcpaa
  • 4
  • 2
7 Comments
 
LVL 10

Expert Comment

by:RONSLOW
ID: 2560744
The value '1' means that it worked.

It could be that (like saome other window styles) this cannot be modified after the window is created.  More correctly, you can change the flag, but it does not change what is there.  This is the case, for example, for combo boxes if you try to change the style from dropdown to dropdownlist.
0
 
LVL 3

Expert Comment

by:SamHobbs
ID: 2561122
My VC 5 documentation says: "To change the view and alignment style after creating the control, use the Windows functions GetWindowLong and SetWindowLong." The documentation does not specify how to change other styles, but if it were possible to, then you probably need to do something like this:

DWORD dwStyle = GetWindowLong(m_hWnd, GWL_STYLE);
if ((dwStyle & LVS_TYPESTYLEMASK) != dwView)
      SetWindowLong(m_hWnd, GWL_STYLE, (dwStyle & ~LVS_TYPESTYLEMASK) | LVS_NOSORTHEADER);
0
 
LVL 10

Expert Comment

by:RONSLOW
ID: 2561764
I'm pretty sure that ModifyStyle actuallydoes that same thing as Get/SetWindowLong internally.

And regardless, there are styles that apply at creation time only .. and changing them later has no effect.  Sad, but true.
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 3

Expert Comment

by:SamHobbs
ID: 2561791
I must admit that I did a quick test to see if I could change LVS_NOSORTHEADER and it did not seem to work, but I was quick enough that I might have done it wrong.

I think it is interesting that the documentation says to use GetWindowLong and SetWindowLong, as if it is important. The documentation is sometimes very misleading, I know. It says that a classes static functions can only call other static functions, but that is not true. Sometimes you need to "read between the lines".

I think that ModifyStyle probably does GetWindowLong and SetWindowLong internally, since a window's style is always available at GWL_STYLE in the extra window memory of a window. Perhaps the reason ModifyStyle does not work might be that it discards the extra bits that list view controls use for style.
0
 
LVL 10

Expert Comment

by:RONSLOW
ID: 2561880
I think the problem is that this change actually creates/destroys windows (it the header control) and so that is why it is only valid at creation time.
0
 

Accepted Solution

by:
Stanislav022200 earned 50 total points
ID: 2562583
Hi.
My list box defined as follows:
------------------
BOOL EComStatView::Create(LPCTSTR lpszClassName, LPCTSTR lpszWindowName, DWORD dwStyle,
                                      const RECT& rect, CWnd* pParentWnd, UINT nID, CCreateContext* pContext)
{
      dwStyle |= LVS_REPORT | LVS_SINGLESEL | LVS_SHOWSELALWAYS;
      return CWnd::Create(lpszClassName, lpszWindowName, dwStyle, rect, pParentWnd, nID, pContext);
}
-------------------
It is sorted perfectly well.
I think that the problem is that this kind of style
must be setted while creation and not during the windw's life.
Try this, hope it will work at your application
0
 
LVL 10

Expert Comment

by:RONSLOW
ID: 2563216
That is what I said.  And it doesn't answer the question.
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
sumHeights  challenge 17 79
Not needed 13 128
moto 4g phone enable finger print 4 42
How do I get Window Title of all opened process? 4 32
Introduction: The undo support, implementing a stack. Continuing from the eigth article about sudoku.   We need a mechanism to keep track of the digits entered so as to implement an undo mechanism.  This should be a ‘Last In First Out’ collec…
In this post we will learn different types of Android Layout and some basics of an Android App.
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.
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…

685 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