Solved

Sorting Header of a listview!!!

Posted on 2000-02-25
7
587 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
[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
  • 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
Independent Software Vendors: 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: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying 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
Login Script to Copy Folders 12 50
Windows Drag & Drop Location 2 115
Hibernate methods 2 87
haveThree challenge 22 126
Introduction: Load and Save to file, Document-View interaction inside the SDI. Continuing from the second article about sudoku.   Open the project in visual studio. From the class view select CSudokuDoc and double click to open the header …
Introduction: Finishing the grid – keyboard support for arrow keys to manoeuvre, entering the numbers.  The PreTranslateMessage function is to be used to intercept and respond to keyboard events. Continuing from the fourth article about sudoku. …
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.
Are you ready to implement Active Directory best practices without reading 300+ pages? You're in luck. In this webinar hosted by Skyport Systems, you gain insight into Microsoft's latest comprehensive guide, with tips on the best and easiest way…

738 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