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
Solved

Sorting Header of a listview!!!

Posted on 2000-02-25
7
583 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
Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

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.

 
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: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

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
Tab names are off by one 5 54
sumDigits challenge 9 170
Sed question 2 100
JQuery serialize and unserialize 8 134
Introduction: Displaying information on the statusbar.   Continuing from the third article about sudoku.   Open the project in visual studio. Status bar – let’s display the timestamp there.  We need to get the timestamp from the document s…
If you use Adobe Reader X it is possible you can't open OLE PDF documents in the standard. The reason is the 'save box mode' in adobe reader X. Many people think the protected Mode of adobe reader x is only to stop the write access. But this fe…
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.
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

792 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