Solved

ListView checkboxes!!??

Posted on 2000-03-02
4
310 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 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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
select query - oracle 16 103
Tidtcpserver listening on multiports? 1 55
MS Access from Delphi 31 100
Can Live bindings change TGrid Cell Colour ? 1 61
Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
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…
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…
This video shows how to use Hyena, from SystemTools Software, to update 100 user accounts from an external text file. View in 1080p for best video quality.

734 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