Custom List View

Posted on 2006-04-15
Medium Priority
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,
Question by:myara
  • 4
  • 3
LVL 49

Expert Comment

ID: 16501558
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

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 Comment

ID: 16501787

  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 ...
P.S. : possible to send a screen copy here ?
LVL 49

Expert Comment

ID: 16502312
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.
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!


Author Comment

ID: 16502416
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 ...
LVL 49

Accepted Solution

DanRollins earned 375 total points
ID: 16502955
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).

Author Comment

ID: 16523017

   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,
LVL 49

Expert Comment

ID: 16528959
The normal way to do drag-and-drop in MFC is described here:

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.  

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

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

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. …
Introduction: Dialogs (1) modal - maintaining the database. Continuing from the ninth article about sudoku.   You might have heard of modal and modeless dialogs.  Here with this Sudoku application will we use one of each type: a modal dialog …
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.
this video summaries big data hadoop online training demo (http://onlineitguru.com/big-data-hadoop-online-training-placement.html) , and covers basics in big data hadoop .
Suggested Courses
Course of the Month16 days, 23 hours left to enroll

864 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