Solved

ListView checkboxes!!??

Posted on 2000-03-02
4
293 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
Hi epsylon i presume you have updates applied? i also do and dont get this error either ..
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Suggested Solutions

Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
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…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…

771 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

10 Experts available now in Live!

Get 1:1 Help Now