Solved

Sorting Header of a listview!!!

Posted on 2000-02-25
7
569 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
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
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

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

This is to be the first in a series of articles demonstrating the development of a complete windows based application using the MFC classes.  I’ll try to keep each article focused on one (or a couple) of the tasks that one may meet.   Introductio…
Introduction: Ownerdraw of the grid button.  A singleton class implentation and usage. Continuing from the fifth article about sudoku.   Open the project in visual studio. Go to the class view – CGridButton should be visible as a class.  R…
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.
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.

746 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

11 Experts available now in Live!

Get 1:1 Help Now