Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

ListView checkboxes!!??

Posted on 2000-03-02
4
Medium Priority
?
334 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 300 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

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

Question has a verified solution.

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

Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
Please read the paragraph below before following the instructions in the video — there are important caveats in the paragraph that I did not mention in the video. If your PaperPort 12 or PaperPort 14 is failing to start, or crashing, or hanging, …
Loops Section Overview
Suggested Courses

610 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