dltigles
dltigles

Reputation: 45

about listview OnDrawItem

procedure TCnCustBuildForm.lstWizardsDrawItem(Sender: TCustomListView;
Item: TListItem; Rect: TRect; State: TOwnerDrawState);

begin

//When first come here, rect.left = 0,   rect.right = 100, which means listview.width = 100.

FillRect(Sender.Canvas.Handle, Rect,  GetStockObject(WHITE_BRUSH));

//....

AutoResizeColumn(TListView(Sender), 0);
//set column 0 width to 173
AutoResizeColumn(TListView(Sender), 0); 
//set column 1 width to 54

//now row width should be 173 + 54 = 227.

I debug the app, with process as follows:

  1. when first call this function, listview.width = 100;

  2. after redraw the first row, call AutoResizeColumn to set listview.width = 227;

  3. then the 2nd time into this function, to redraw the second row, now the rect param changed, rect.width = 227;

  4. So FillRect function should Fill a rectangle of width = 227, but it only fill width = 100, this means not clean all the row?

BTW: For why I ask this question, cause of each time I draw the second column to the right, the previous data of the second column remains, so it seems as 3 rows(the middle row is previous place of the true 2nd row, which should be cleaned ,but not).

Upvotes: 0

Views: 503

Answers (1)

Pat
Pat

Reputation: 236

You shouldn't be doing anything inside the DrawItem event handler except drawing the item based on the current state of everything, including the column widths. Then when anything about the list view changes that requires an item to be drawn, DrawItem will fire. Don't change the column widths inside DrawItem. Change them elsewhere, then if the change requires an item to be drawn, DrawItem will be called.

Upvotes: 2

Related Questions