Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Checkboxes in CListCtrl via StateImages

Posted on 1997-11-05
3
Medium Priority
?
440 Views
Last Modified: 2013-11-20
I'm looking for a solution:
I intend to implement a CListCtrl (Reportstyle) with Checkboxes at the head of each line (like CCheckBox).
I've created two state icons (checked, unchecked). But the problem that occured was that if I try to click on the checkbox nothing changed respectively the state of another line which was selected changed. Furthermore I don't only want to change thy state but to open an dialog at a double click to get more information from the user.
Thus my accurate questions:
- How can I include the checkbox range into the selection?
- How can I change the state of the checkbox by a single click on the checkbox field (like the CListBox behaviour)?
- How can I effectively open an dialog by a double click (Override WM_...)?
- How can I simply implement a functionality for exchanging two lines? I've tried this but every time the selection of the line I wanted to go down or up was gone.

I would be very grateful if if you could could show me the source code for a 3 row Control like discribed above.
Thank in advance.
0
Comment
Question by:trouvain
[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
3 Comments
 
LVL 8

Expert Comment

by:gelbert
ID: 1309387
Take a look at samples\mfc\general\rowlist. To open dialog overide handle of WM_LBUTTONDBLCLK in your CListCtrl derived class and create and open dialog inside this function.
0
 
LVL 10

Accepted Solution

by:
RONSLOW earned 400 total points
ID: 1309388
I have code that does all this for a list control

Probably a bit much to put up in detail here.

To add checkboxes...

void CMyListCtrl::AddExStyle(DWORD dwNewStyle) {
      DWORD dwStyle = GetExStyle();
      dwStyle |= dwNewStyle;
      SetExStyle(dwStyle);
}

void CMyListCtrl::RemoveExStyle(DWORD dwDelStyle) {
      DWORD dwStyle = GetExStyle();
      dwStyle &= ~dwDelStyle;
      SetExStyle(dwStyle);
}

void CMyListCtrl::EnableCheckboxes(bool enable) {
      if (enable) {
            AddExStyle(LVS_EX_CHECKBOXES);
      } else {
            RemoveExStyle(LVS_EX_CHECKBOXES);
      }
}

To detect a checkbox change...

void CMyListCtrl::OnItemchanged(NMHDR* pNMHDR, LRESULT* pResult) {
      NM_LISTVIEW* pNMListView = (NM_LISTVIEW*)pNMHDR;
      UINT changes = (pNMListView->uNewState)^(pNMListView->uOldState);
      if (changes & LVIS_STATEIMAGEMASK) {
            UINT checkstate = ((pNMListView->uNewState&LVIS_STATEIMAGEMASK) >> 12)-1;
            CheckStateChanged(pNMListView->lParam,checkstate);
      }
      *pResult = true;
}

where CheckStateChanged is a member function that gets called whenever a check state is changed

for double click...

ON_NOTIFY_REFLECT(NM_DBLCLK, OnDblclk)

int CMyListCtrl::HitTestMessage() const {
      const MSG * pMsg = GetCurrentMessage();
      CPoint pt = pMsg->pt;
      ScreenToClient(&pt);
      return HitTest(pt);
}

void CMyListCtrl::OnDblclk(NMHDR* /*pNMHDR*/, LRESULT* pResult) {
      m_clickitem = -1;
      int item = HitTestMessage(&col,NULL,&flag);
      if (item >= 0) {
            // handle double click (eg call dialog)
      }
      *pResult = 0;
}

exchanging two lines looses selection...

void CMyListCtrl::PreSubclassWindow() {
      CListCtrl::PreSubclassWindow();
      // .. other stuff
      ModifyStyle(0,LVS_SHOWSELALWAYS);
}

Hope this helps.

0
 

Author Comment

by:trouvain
ID: 1309389
Thsnx but you could be more specific
0

Featured Post

Survive A High-Traffic Event with Percona

Your application or website rely on your database to deliver information about products and services to your customers. You can’t afford to have your database lose performance, lose availability or become unresponsive – even for just a few minutes.

Question has a verified solution.

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

Here is how to use MFC's automatic Radio Button handling in your dialog boxes and forms.  Beginner programmers usually start with a OnClick handler for each radio button and that's just not the right way to go.  MFC has a very cool system for handli…
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. …
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…

705 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