Solved

ListView checkboxes!!??

Posted on 2000-03-02
4
296 Views
Last Modified: 2010-04-04
Why is it that when I add an item to a TListView with checkboxes, all items become unchecked?

And how can I remedy this? (I am using D4)

I have found a work-around myself, but it's kind of complicated, I am looking for a simple solution.
0
Comment
Question by:nrico
  • 2
4 Comments
 
LVL 5

Expert Comment

by:TheNeil
ID: 2576041
Why not just do this:

VAR
  CheckState : TStringList;
  iCount : LONGINT;
BEGIN
  CheckState := TStringList.Create;
  FOR iCount := 0 TO (ListBox1.Items.Count - 1)
  DO
    IF ListBox1.Checked[iCount]
    THEN
      CheckState.Add('1')
    ELSE
      CheckState.Add('0');
 
//Add your new item

  FOR iCount := 0 TO (CheckState.Items.Count - 1)
  DO
    ListBox1.Checked[iCount] :=  (CheckState[iCount] = '1');

  CheckState.Free;
END;

It's not ideal and I don't know why Delphi is being a pain but it'll fix your problem

The Neil
0
 
LVL 13

Expert Comment

by:Epsylon
ID: 2576155
I don't have that problem. The boxes remain checked. I wonder how you add a new item.
0
 
LVL 17

Accepted Solution

by:
inthe earned 75 total points
ID: 2576196
Hi
this is a bug with the component see this report from

http://www.borland.com/devsupport/delphi/fixes/delphi4/vcl.html#win 32 controls\tlistview

Area: vcl\win 32 controls\tlistview
Reference Number: 1065 (Published: 10/27/98)

Status: Fixed in Version 4 Update Pack 2
Date Reported: 8/1/98

Severity: Serious

Type: Basic Functionality Failure

Problem:

The TListView class clears the checked property of
all items when an item is manually added and its
Checked property is set to TRUE


Steps:

1.  Create a new applicatoin.
2.  Drop a TButton and a TListview on the form.
3.  Add a bunch of items to the Listview in the OI
4.  Set the Listview's Checked property to True
5.  Add this code to the OnClick of the button --

procedure TForm1.Button2Click(Sender: TObject);
var
  ListItem: TListItem;
begin
  ListItem := Listview1.Items.Add;
  ListItem.Caption := 'Added item';
  ListItem.Checked := True;
end;


6.  Run the application.   Select the checkboxes of
any or all of the items.  Then press the button.

Notice that the checked properties of all of the
items are cleared.



so the answer is too apply update pack 2 which you an also get from borlands devsupport site.

http://www.borland.com/devsupport/delphi/downloads/index.html#Delphi 4
Regards Barry
0
 
LVL 17

Expert Comment

by:inthe
ID: 2576207
Hi epsylon i presume you have updates applied? i also do and dont get this error either ..
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
This tutorial gives a high-level tour of the interface of Marketo (a marketing automation tool to help businesses track and engage prospective customers and drive them to purchase). You will see the main areas including Marketing Activities, Design …
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…

867 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

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now