Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Sorting Header of a listview!!!

Posted on 2000-02-25
7
Medium Priority
?
597 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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
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 100 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

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

Question has a verified solution.

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

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. …
Have you tried to learn about Unicode, UTF-8, and multibyte text encoding and all the articles are just too "academic" or too technical? This article aims to make the whole topic easy for just about anyone to understand.
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 this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…

636 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