I am having a problem with a CheckListBox where the Style is set to
lbVirtualOwnerDraw. I have no problems when populating the CheckListBox.
The population of the CheckListBox is triggered when I set the Count
property to the number of items in the underlying list i.e.
(CheckListBox1.Count := MyItems.Count;)
I want to clear the CheckListBox in the form's OnDeactivate event so
that I can populate it with other strings on re-activating the form. I
have tried a simple Clear method (CheckListBox1.Clear) but this does not
reset the Count property to 0. So I have added in the code to set this
to 0 (CheckListBox1.Count := 0;). If nothing has been ticked I do not
have a problem when the OnDeactivate event is trigered however if
something has been ticked then I get the following error message -
"Error setting CheckListBox1.Count"
Any suggestions on what I am doing wrong.
Michael.
>"Error setting CheckListBox1.Count"
Setting Count sends an LB_SETCOUNT message to the control. The control
is returning LB_ERR or LB_ERRSPACE. Since the new count value is zero,
something else has the control ticked off. I can't reproduce the
problem though.
Good luck.
Kurt
Thanks for your reply, unfortunately I have not been able to get past
this error. To give you more detail -
Delphi 7.0
Windows 98 (Build 4.10.2222 A)
I have created a new application that only does what is necessary to
replicate the problem. The application has two forms, the first form has
a button on it. In the button's OnClick event is -
Form2.ShowModal;
Form2 has a CheckListBox dropped onto it with its style set to
lbVirtualOwnerDraw
Form2's OnActivate contains -
MyList := tStringlist.Create;
for I := 0 to 5 do
MyList.Add('Item' + IntToStr(I));
CheckListBox1.Count := MyList.Count;
Form2's OnDeactivate contains -
CheckListBox1.Count := 0;
MyList.Free;
CheckListBox1's OnData contains -
Data := MyList[Index];
To replicate the problem: run the program, click on the button, tick an
item in the list then close form2. (You must tick something before closing).
Can you confirm that this does not replicate the problem on your machine.
Thanks,
Michael.
>Windows 98 (Build 4.10.2222 A)
It doesn't happen for me, but I'm running Windows 2000. There is a
note that Win95/98 has a limit of 32767 on the Count parameter, but
that should not be an issue here.
You might try adding a button to Form2 and set the count to 0 there to
see if it is a timing related issue. Also, if Form2 is being destroyed
on closing / deactivation, the window handle might be invalid causing
the error.
Good luck.
Kurt
Thanks, I tried what you suggested and I still have the same problem. I
will see if I can find out if there is a Microsoft upgrade to the
underlying listbox component, maybe there is a bug in that.
Thanks,
Michael.
Further to my other problem I have found that the OnDrawItem will fire
when the Style is set to lbVirtual. From my understanding, when the
Style is lbVirtual, the OnDrawItem should be ignored as it is when the
Style is set to lbStandard.
Regards,
Michael.
>Further to my other problem I have found that the OnDrawItem will fire
>when the Style is set to lbVirtual. From my understanding, when the
>Style is lbVirtual, the OnDrawItem should be ignored as it is when the
>Style is set to lbStandard.
I can confirm that. Actually, the OnDrawItem gets called unless Style
is lbStandard. In fact there's special code to ignore an OnDrawItem
event handler if it is lbStandard. I haven't traced into it in detail,
but I suspect this is because a TCheckListBox is always "owner draw",
even when Style is lbStandard.
Good luck.
Kurt
Thanks for all your help.
As a final note I have tried this on various machines and have found it
to be common accross all of them so I have posted a bug report on
QualityCentral, report number 5503.
Thanks,
Michael.