We help IT Professionals succeed at work.

Custom List View

myara
myara asked
on
Medium Priority
287 Views
Last Modified: 2013-11-20
Dear Experts Exchange,
  I try to build my own list view. I'd like each row to be the following :
  |----|   |----|
  | B1 |  | B2 |      Text
  |----|  |----|
B1 and B2 being (for now) CButtons.
My actual code is organised this way :
  - a "CRow : public CView" Object describing a line (contains 2 buttons instances, one for B1 and one for B2 + a custom drawing fuction drawing the text)
  - a "CMyList" : public CView" Object describing the list itself. This object makes for now only 2 instances of CRow (that's a preliminary test class).

  CMyList is registered as a Custom MFC Object, declared in the resource file as a child view for a CDialogBar.

  My main problem is a Focus Problem I think : only the first row instance tracks both buttons clicks. Trying things such as SetFocus() for the second line does not seem to work, as the only messages tracking view is still the first row.

  A subsidiary question : Is it possible to call only the drawing function of a CButton in the OnPaint function of a custom object ?

  Best Regards,
   Mike
Comment
Watch Question

CERTIFIED EXPERT
Author of the Year 2009

Commented:
Is your goal to have buttons in the first two columns of a multiple-colum list view?  And (for instance) when the list is scrolled, the buttons scroll with the row?

If so, you have some significant work ahead of you.  I'd recommend using an existing control, derived from CListCtrl that has that sort of functionality built into it.  For instance, see
   Adding Controls to listcontrol
   http://www.codeguru.com/cpp/controls/listbox/article.php/c4761/

Even if you do not want to use that specific control, the sources code is provided so that you can learn the needed techniques for incorporation into yur own controls.

-- Dan

Author

Commented:
Hello,

  thanks for your advice, I already had a look to this article but that's not exactly what I wanted to do.

I found a "not so bad" solution : the Line View is derived from CDialog, and my custom List View is derived from CScrollView. This way I've no problem of "focus". My only problem for now is that one button per line has the "black frame" around itself. I think there's a message-problem but I don't know how to solve it ...

  Thanks once more ...
    Mike
P.S. : possible to send a screen copy here ?
CERTIFIED EXPERT
Author of the Year 2009

Commented:
EE doesn't have that ability ... if you post the image somewhere (say on a free picture-sharing site), then you can put a link to it in your comment... but that's about the best that can be done.

As to the "black frame" -- I think you are talking about the so-called "focus rectangle"  That is supposed to be there -- it indicates which controls has the keyboard focus.

It this point, I don't really know what techniques you are using, but if you are doing almost any form of OwnerDraw on a CListCtrl, then that will relate to the "item state" -- one of its values is LVIS_FOCUSED (the relevant message is LVM_GETITEMSTATE and/or LVM_SETITEMSTATE).

You might also be talking about the larger darker rectangle that indicates the "Default Button" in a dialog.  It indicates which action the program should take when the user presses the Enter key. That is a property of the dialog item and you can change it by sending a BM_SETSTYLE to turn off the BS_DEFPUSHBUTTON style bit.  The DM_SETDEFID message is also related.

Author

Commented:
Yes the black frame is the "focus rectangle", not the "default button" (I removed its state in the resource).
I think the problem is that, in MFC, the "focus" does not go through a CScrollView : the "main dialog" (the floating tool) cannot (I think) forward it messages to through the ScrollView (perhaps I mistake), and thus it can be more than one "focused" button at one time in a single dialog box. Is it possible to send to you my code ? Perhaps can I put it in a mini web site and give you the link ?

  Thanks once more for your interest ...
     Mike
CERTIFIED EXPERT
Author of the Year 2009
Commented:
It sounds like you are doing some non-standard and very complex things... It might be that after fixing this particular problem, you just end up with a "fixed" version of an unweildy and non-standard U/I interface method that will certainly present many additional problems along the line.

You can try zipping up the entire project and posting it somewhere on the web... but I won't promise that I'll look at it (maybe some other Expert here might).

Not the solution you were looking for? Getting a personalized solution is easy.

Ask the Experts

Author

Commented:
Hello,

   Thanks to your help, I finally found a solution : As you said, using a CScrollView to scroll a dialog is not standard, so I implemented a kind of CScrollDialog (derived from CDialog) and this time it works.  So thanks a lot for your advice.

  I have two questions more :
   - Is OLE the "good way" to handle Drag 'n' Drop in MFC ?
   - Drawing during mouse events (OnMouseMove) does not seem to work. Is there a way to do this, or may I change my OnPaint Override and invalidate the Wnd ?

   Thanks once more,
      Mike
CERTIFIED EXPERT
Author of the Year 2009

Commented:
The normal way to do drag-and-drop in MFC is described here:
   http://msdn2.microsoft.com/en-us/library/96826a87(vs.80).aspx

You probably should not be drawing things in your OnMouseMove handler during a drag-and-drop operation.   If you want to change the image of what is being dragged, you make calls to affect the CImageList that gets set up during the OnBegindrag() call.  For instance, CImageList::SetDragCursorImage() and so forth.  Also, look at the CImageList::DragShowNolock() function which relates to locking window updates during drag operations.  
Access more of Experts Exchange with a free account
Thanks for using Experts Exchange.

Create a free account to continue.

Limited access with a free account allows you to:

  • View three pieces of content (articles, solutions, posts, and videos)
  • Ask the experts questions (counted toward content limit)
  • Customize your dashboard and profile

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.