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
Solved

ListView checkboxes!!??

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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering 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
TEMBEDDEDWB how can i change its user agent ? 8 69
CheckListBox usage 3 71
enhance the following code 3 37
How to save the image in the .cds File ClientDataSet? 1 22
Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
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…
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

808 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