Click here to Skip to main content
16,022,669 members
Please Sign up or sign in to vote.
4.50/5 (2 votes)
See more:
Gentle people,

I am at wits end. There is a program I am supposed to change. It contains a simple single-selection listbox containing file names (in reverse order - youngest on top). All of this works properly. Unfortunately the listbox is rather large and featureless, hence the desire was uttered to have horizontal grid lines to separate the file names. No problem, I thought, set the property GridLinesHorizontal to BorderThinSolid and you are done. Well, to err is human! After reading hundreds of pages on the internet, the only thing I could find is:

C++
ListBox.GridLinesHorizontal = 3 (or ListBox.BorderThinSolid);

or a simple sentence stating "set the GridLinesHorizontal to BorderThinSolid"!

But not the slightest hint how this can be done! Where does "ListBox." or whatever come from? It ought to be a class, or a structure, or ... I always entertained the thought this must be a structure, for it contains values, but I have no idea what type of structure this may be, nor how it is defined. The same applies to BorderThinSolid. Apparently a constant. No idea where it can be found ...

Where did I go in the wrong direction? I am at wits end!
Can you help?
Kind regards!

N.B. This may be of interest:
C++
InitCtrls.dwICC = ICC_LISTVIEW_CLASSES || ICC_STANDARD_CLASSES || ICC_USEREX_CLASSES;
Posted
Updated 16-May-12 10:17am
v2

Thank you all for your comments!

Jochen, I apologize for my (persistent) typo. Of course, there should be only a single "|".

Michael, I think I have to disappoint you. All of the above I found in official MSDN ListBox Control documentations. No proprietary libraries involved. However, I suspect it may only be true for specific environments. (e.g. me.GridLinesHorizontal reminds me strongly of Visual Basic in MS ACCESS ...)
Unfortunately, this is a WinApi program, not MFC. (and honestly - I don't know anything about MFC), but the result when compiling the program is an error message complaining about the wrong qualifier ("me.", "ListBox1.", etc.). The term "GridLinesHorizontal" itself is known to the compiler. Hence my problem seems to boil down to the question - what is this qualkifier supposed to address and how is it defined.

If I am not able to solve this, I will have to look into ListView ...
 
Share this answer
 
Comments
michaelmel 17-May-12 20:42pm    
Ernst, just a few points there:

1) There should be something like GetListCtrl method in List View class (I know I keep thinking about MFC but relationship between views and underlying controls is implemented similarly on all SDKs) which should return a handle to the list box object which is what you want I think.

2) Re compiler errors - C/C++ compilers will only complain about unknown object without even checking what is being dereferenced on that object. E.g. if ListBox1 is unknown, they will tell you about it (e.g. undeclared identifier error) and stop analyzing the rest of that statement. What I am saying is there is a flaw in the logic of assuming that "term GridLinesHorizontal itself is known to the compiler". Only if the object is known you will get messages such as "GridLinesHorizontal is not a member of ListBox1".

Sorry if I misunderstood the question and made some wild assumptions as to what you wanted.
Ernst G. Gruber 18-May-12 5:27am    
Michael, thanks again for your remarks!

ad 1) To get a handle to the listbox is not a problem. It is returned by the CreateWindowEx function when creating the listbox. Unfortunately the handle isn't of any use, because - at least in my understanding - a handle can be anything, but isn't a pointer to the structure I am looking for. Further reading in MSDN documentation revealed another intriguing sentence - "The control structure of a list box and its tab stop settings is allocated from the heap ...", but again no hint how this control structure can be accessed ... :O((

ad 2) This is what I used to think. But - at least the compiler I am using, MS VC++ 2008 - returns from the line <pre lang="c++">listbox1.GridLinesHorizontal = listbox1.BorderThinSolid;</pre> both errors. Hence, I thought, GridLinesHorizontal is already checked and accepted. But you may be right - it's the same error in both cases and they may override other errors ...

Well, one can't win them all ....
I suspect you found some documentation on a proprietary library. What probably happens is that the library gives the users an interface to a class derived from CListBox. Therefore the new puzzling variables/properties/constants are a part of their new class wrapper not of the basic list box. Needless to say you cannot write ListBox.GridLinesHorizontal = 3 if you don't use that library.

The bad news is that basic Windows ListBox and/or MFC CListBox itself is rather inflexible and I don't think it would allow you to do what you want without writing a whole bunch of stuff (but fast forward to the end of my message for a glimmer of hope).

For example, in MFC versions that came with Visual Studio 2005 and earlier the standard list box did not have a mode where selection highlighted the whole row (which people normally want to see) - instead only the first column could be selected. There are ways to overcome it - again a class could be derived from CListBox and implement this behaviour but it is not a ten minute job (well at least not for me).

However I believe VStudio 2010 comes with an improved MFC version which has a new expanded list box class (called something other than CListBox, can't remember exactly) which allows selecting a single whole row in a list box. I don't have VStudio 2010 but may be they also expanded it in other ways and possibly added something like optional grid lines into it. So maybe it is worth looking into it.
 
Share this answer
 
v2
A search for 'GridLinesHorizontal BorderThinSolid' leads to the Real Software ListBox [^] control.

The line
C++
InitCtrls.dwICC = ICC_LISTVIEW_CLASSES || ICC_STANDARD_CLASSES || ICC_USEREX_CLASSES;

seems to be wrong. The variable is initialized with the boolean value true. Probably it should be:
C++
InitCtrls.dwICC = ICC_LISTVIEW_CLASSES | ICC_STANDARD_CLASSES | ICC_USEREX_CLASSES;
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900