Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

SetItem in multiselection and onwerdraw

Status
Not open for further replies.

pierreb

Programmer
Mar 12, 2002
2
NL
I created a ownerdraw, Report style, CExListCtrl. This class is derived from CListCtrl (MFC). I have overwritten OnKeyDown (and more) to catch key strokes and mouse button clicks. I'm using OnKeyDown to catch all navigating keyhits (arrow keys, pageup, pagedown, ...). The ExListCtrl displays columns. I fetch the item and subitem state to draw the columns. This is done because I also want to select separate columns and not only the whole row. In the DrawItem of the ExListCtrl I’m using GetItem to retrieve the state of each column in a row and draw the column. This way the row is painted. This works fine, but I also implemented a multiselection. While holding shift or Ctrl I can select rows (not separate columns). The selection of a row will cause all subitems (columns) of that row to receive a new state (LVIS_SELECTED | LVISFOCUSED) done with SetItem. When I select a second row while holding shift or ctrl by clicking it or using the arrowdown or arrowup keys the selection is added but the first column (and only the first column) of the previous row(s) is suddenly displayed in gray. This means (and I checked the state) that it has lost its focus state somehow. I isolated the code and after the SetItem call with the new state of the new selection that is added the first column(s) of the previous selections lose there focus.

Somehow the state of the previous rows is affected when I change the other with SetItem or SetItemState. I think the reason that only the first column is affected is because in report style the subitems are not used by the CListCtrl class. I tried to send the LVI_SETITEM Message rather than using SetItem or SetItemState, but the effect is the same.

Does someone know what I can do to prevent the CListCtrl to alter the ListCtrl items?
Is there some other way to alter the state of the items / subitems in a listctrl?
If the state is set correct the paint will automatically use the right colors. Or should I check for multiselection in the DrawItem because maybe only one row can have the focus at the same time?

Thanks in advance!
Pierre Bakker
NL
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top