Board index » cppbuilder » How add subitem when set ownerdraw=true

How add subitem when set ownerdraw=true

I find when I set ownerdraw=true,subitem will not show and I can't
receive event OnCustomDrawSubItem.
What's wrong?
 

Re:How add subitem when set ownerdraw=true


Hi Kaven,

Quote
> I find when I set ownerdraw=true,subitem will not show and I can't
> receive event OnCustomDrawSubItem.
> What's wrong?

The OwnerDraw property (LVS_OWNERDRAWFIXED style) cannot be used in conjunction
with the Custom Draw service.  If you are indeed using the OnCustomDrawItem and
OnCustomDrawSubItem events, leave the OwnerDraw property at false.  Otherwise,
don't use the Custom Draw service: set the OwnerDraw property to true, then use
the OnDrawItem event to render an entire row at a time (this is significantly
more difficult than using the Custom Draw service).

Good luck!

--
Damon Chandler
http://bcbcaq.freeservers.com

Re:How add subitem when set ownerdraw=true


This is a big bug.

Re:How add subitem when set ownerdraw=true


Quote
: Kaven <kav...@bigfoot.com> wrote:
>This is a big bug.

Could you please provide a test case?

--
General information:
  * Post to the right group - http://www.borland.com/newsgroups/
    * Do not cross- or multipost
      * Research at http://www.mers.com/searchsite.html

Stefan Hoffmeister - http://www.econos.de/
TeamB - http://www.teamb.com/

Re:How add subitem when set ownerdraw=true


On Sat, 22 Jan 2000 15:27:12 +0100, "Stefan Hoffmeister (TeamB)"

Quote
<Stefan.Hoffmeis...@Econos.de> wrote:
>: Kaven <kav...@bigfoot.com> wrote:

>>This is a big bug.

>Could you please provide a test case?

#include <vcl.h>
#pragma hdrstop

#include "Unit1.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm1 *Form1;
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
        : TForm(Owner)
{
ListView1->OwnerDraw=true;//set OwnerDraw to true

Quote
}

//---------------------------------------------------------------------------

void __fastcall TForm1::ListView1CustomDrawItem(TCustomListView
*Sender,
      TListItem *Item, TCustomDrawState State, bool &DefaultDraw)
{ Sender->Canvas->Pen->Width=1;
  Sender->Canvas->Pen->Color = clRed;
  Sender->Canvas->PenPos=Item->Position ;
  Sender->Canvas->LineTo((int)Item->Position.x+20,
(int)Item->Position.y+10);
  //DefaultDraw=false;

Quote
}

//---------------------------------------------------------------------------
void __fastcall TForm1::FormCreate(TObject *Sender)
{
  TListItem *pItem;
  for (int i = 0; i < 10; i++)
  {
    pItem = ListView1->Items->Add();
    pItem->Caption = "Image" + IntToStr(i);
    pItem->ImageIndex = -1;
    pItem->SubItems->Add(IntToStr(i)+"sub1");
    pItem->SubItems->Add(IntToStr(i)+"sub2");
    pItem->SubItems->Add(IntToStr(i)+"sub3");
  }
Quote
}

//---------------------------------------------------------------------------

void __fastcall TForm1::ListView1CustomDrawSubItem(TCustomListView
*Sender,
      TListItem *Item, int SubItem, TCustomDrawState State,
      bool &DefaultDraw)
{
 /*.....
code at here  never will be run if you dont set ownerDraw to false.
But help file is  "Set OwnerDraw to true to allow the list view to
receive custom draw events (OnCustomDraw, OnCustomDrawItem, and
OnCustomDrawSubItem)." So I think either vcl or help file is wrong.
If I am wrong or other way to get rid of this problem , please let me
know.*/

Quote
}

//---------------------------------------------------------------------------
Thanks

 Kaven

Re:How add subitem when set ownerdraw=true


Hi Kaven,

Quote
> void __fastcall TForm1::ListView1CustomDrawSubItem(TCustomListView
> *Sender, TListItem *Item, int SubItem, TCustomDrawState State,
>  bool &DefaultDraw)
> {
>  /*.....
> But help file is  "Set OwnerDraw to true to allow the list view to
> receive custom draw events (OnCustomDraw, OnCustomDrawItem, and
> OnCustomDrawSubItem)."
>}
> So I think either vcl or help file is wrong.

The help file is wrong.  The TCustomListView implementation has to set the
LVS_OWNERDRAWFIXED ListView style for the OwnerDraw property to have any meaning
(i.e., without the style, the ListView's Parent would never receive the
WM_DRAWITEM message => the ListView would never receive the CN_DRAWITEM message
=> the OnDrawItem event handler would never fire).  Setting this style, however,
will conflict with the Custom Draw service.  For ListViews, the owner-drawn
approach suffers from the the following...

(1) It only applies to vsReport ViewStyles;
(2) Implementing an OnDrawItem event handler is much more involved as each
    row needs to be drawn in its entirety;
(3) It is old technology;

Unless your target platform has a comctl32.dll version less than 4.70, use the
Custon Draw service (i.e., keep the OwnerDraw property at false).

Good luck!

--
Damon Chandler
http://bcbcaq.freeservers.com

Other Threads