Checkboxes are not scrolling in TListView component

I've created ListView and added checkboxes to check each row if needed. All was fine until there was a lot of items in the listview so that it needed scolling. I checked on line and then I saw that checkboxes are not scrolling with other content if I scroll the scrollbar.

My code:

unit ShareCommissionDialog; interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls, sButton, ComCtrls, sListView, sCheckBox, DataManager; type TdlgShareCommission = class(TForm) lvEmployees: TsListView; btnCancel: TsButton; btnDone: TsButton; procedure FormCreate(Sender: TObject); procedure FormShow(Sender: TObject); procedure FormClose(Sender: TObject; var Action: TCloseAction); procedure btnDoneClick(Sender: TObject); procedure btnCancelClick(Sender: TObject); private manager: TDataManager; ListViewCheckBoxList: TList; employeeIDs: TStringList; procedure ListViewCheckBoxCreate(List: TsListView; employeeID: string; R: TRect); procedure ListViewCheckBoxClick(Sender: TObject); procedure ListViewCheckBoxSelected(item: Integer; List: TsListView); procedure ListViewCheckBoxUnselected(item: Integer; List: TsListView); procedure PopulateEmployees; procedure ShowSelectedEmployees; procedure MarkRows; public property DataManager: TDataManager read manager write manager; property CommissionReceivers: TStringList read employeeIDs write employeeIDs; end; var dlgShareCommission: TdlgShareCommission; implementation {$R *.dfm} procedure TdlgShareCommission.btnCancelClick(Sender: TObject); begin employeeIDs := employeeIDs; end; procedure TdlgShareCommission.btnDoneClick(Sender: TObject); var i, j: Integer; begin employeeIDs := TStringList.Create; for i := 0 to ListViewCheckBoxList.Count - 1 do begin if TsCheckBox(ListViewCheckBoxList[i]).Checked then begin for j := 0 to manager.Data.Employees.Count - 1 do begin if TsCheckBox(ListViewCheckBoxList[i]).Tag = StrToInt(manager.Data.Employees[j].ID) then begin employeeIDs.Add(manager.Data.Employees[j].ID); Break; end; end; end; end; end; procedure TdlgShareCommission.FormClose(Sender: TObject; var Action: TCloseAction); begin manager.GetEmployees(manager.Data.SelectedPOS.ID); end; procedure TdlgShareCommission.FormCreate(Sender: TObject); begin ListViewCheckBoxList := TList.Create; end; procedure TdlgShareCommission.ListViewCheckBoxCreate(List: TsListView; employeeID: string; R: TRect); function NewViewCheckBox: TsCheckBox; begin Result := TsCheckBox.Create(Self); Result.Tag := StrToInt(employeeID); Result.Parent := List; Result.BoundsRect := R; Result.Checked := False; Result.OnClick := ListViewCheckBoxClick; end; begin ListViewCheckBoxList.Add(NewViewCheckBox); end; procedure TdlgShareCommission.FormShow(Sender: TObject); begin if employeeIDs <> nil then begin PopulateEmployees; ShowSelectedEmployees; MarkRows; end else begin PopulateEmployees; MarkRows; end; //PopulateEmployees; //MarkRows; end; procedure TdlgShareCommission.ListViewCheckBoxClick(Sender: TObject); var i: Integer; begin for i := 0 to ListViewCheckBoxList.Count - 1 do begin if (i+1) <= (ListViewCheckBoxList.Count - 1) then if not TsCheckBox(ListViewCheckBoxList[i+1]).Enabled then begin TsCheckBox(ListViewCheckBoxList[i+1]).Checked := TsCheckBox(ListViewCheckBoxList[i]).Checked; end; end; MarkRows; end; procedure TdlgShareCommission.MarkRows; var j: Integer; begin for j := 0 to lvEmployees.Items.Count - 1 do begin if not TsCheckBox(ListViewCheckBoxList[j]).Checked then begin ListViewCheckBoxSelected(j, lvEmployees); end else begin ListViewCheckBoxUnselected(j, lvEmployees); end; end; end; procedure TdlgShareCommission.ListViewCheckBoxSelected(item: Integer; List: TsListView); begin with List do begin Items[item].Selected := False; end; end; procedure TdlgShareCommission.ListViewCheckBoxUnselected(item: Integer; List: TsListView); begin with List do begin Items[item].Selected := False; end; end; procedure TdlgShareCommission.PopulateEmployees; var i: Integer; R: TRect; employeeRow: TListItem; begin with lvEmployees do try Items.BeginUpdate; Items.Clear; manager.GetEmployees(manager.Data.SelectedPOS.ID); for i := 0 to manager.Data.Employees.Count - 1 do begin employeeRow := Items.Add; R := Items[i].DisplayRect(drBounds); R.Left := 5; R.Top := R.Top + 1; ListViewCheckBoxCreate(lvEmployees, manager.Data.Employees[i].ID, R); Items[i].Data := TsCheckBox(ListViewCheckBoxList[i]); employeeRow.SubItems.Add(manager.Data.Employees[i].FirstName + ' ' + manager.Data.Employees[i].LastName); end; finally lvEmployees.Items.EndUpdate; end; end; procedure TdlgShareCommission.ShowSelectedEmployees; var i, j: Integer; begin for j := 0 to lvEmployees.Items.Count - 1 do begin for i := 0 to employeeIDs.Count - 1 do begin if TsCheckBox(ListViewCheckBoxList[j]).Tag = StrToInt(employeeIDs[i]) then begin TsCheckBox(ListViewCheckBoxList[j]).Checked := True; end; end; end; end; end.

What I need to add to code that checkboxes also will scroll with other content?

--------------Solutions-------------

The standard ListView has a property called checkboxes that can be set to true.
If you use that then you don't have to mess with making your own checkboxes.
I've never had any problems with checkboxes not showing properly in this control.

This property works best in ViewStyle:= vsList or ViewStyle:= vsReport

Alternatively if you want checkboxes on some items but not on others then make a picture of a checkbox (1 unchecked, 1 checked) and add both of them to an ImageList.
If an item needs a checkbox, set its ImageIndex property to that of the unchecked item. If it needs to be checked, set its ImageIndex property to the checked Image.
This works in ViewStyle:= vsReport and ViewStyle:= vsList.

You are using a custom ListView (TsListView) control, try using a standard ListView instead and see if the strange behaviour shows up.

Category:delphi Time:2011-04-24 Views:2

Related post

  • IE7: checkboxes don't scroll with containing li, display inappropriately 2011-12-29

    I have a <ul> containing several vertically stacked <li>. The <li> scroll within the <ul>, and there are checkboxes contained within the <li>. In IE7, these checkboxes don't scroll with along with their containing <li

  • How to add scroller for custom component in as 3? 2014-04-15

    I have a custom component with some properties. Now I want to add scroller for this component. I don't have any idea about it. I want to add this scroller in ActionScript file. Not in MXML file. Can anyone help me out from this? Update: <s:Scrolle

  • Telerik - WPF - RadGridView Filter - How to set checkbox container to scroll? 2011-11-15

    I'm still pretty green to WPF, and I'm trying to figure out how to work with a Telerik RadGrid for WPF. The grid has a filter that automatically populates with checkboxes for every value in the field. You can see the problem this creates below: Is th

  • trouble with scrolling a UIScrollBar component within a class 2008-09-11

    I'm trying to attach an instance of UIScrollbar component to a dynamic text field inside of an instance of a class that is being made after some XML is loaded. The scroll bar component is getting properly attached, as the size of the slider varies de

  • Adobe Flex/AIR: Scrolling a sub-component, not the whole window 2008-12-10

    I'm developing an application with Adobe Flex and AIR, and I've been banging my head against the wall trying to figure out how to solve a scrolling issue. The basic structure of my main application window (simplified greatly) is this: <?xml versio

  • Silverlight ListBox triggering CheckBox events when scrolled 2011-06-17

    I've got a list box where the items are check boxes. When the list box is scrolled I am finding that the Checked and Unchecked events are firing for items as they either scroll into view or scroll out of view. It seems related to what this post discu

  • adding a scroller around a component tag 2011-08-26

    i have a group tag as given below but i am getting the error:'Scalar value nodes may not be state-specific' <s:Group includeIn="newTask,branchingGroup,model_chain,model,condition"> <components:NewTask id="taskId" includeIn="newTask"/>

  • Check in checkbox missing when scrolling up/down 2012-01-29

    Hello everyone i have a problem in my application. The check in my check box, once i check the check box and scroll it down/up the check is gone, i didn't know how that happen. can anyone help me with this? THANKS for the help :) HERE IS MY CODE: pub

  • TListView with CheckBoxes and SubItemImages 2010-02-25

    Using the standard TListView component (ViewStyle = vsReport), I have attached a TImageList and have successfully added images to both the first column (Item.ImageIndex := 0) and to the subsequent columns (Items[0].SubItemImages[1] := 1). If I then s

  • TListView and mouse wheel scrolling 2011-03-14

    I have a TListView component in a form. It's quite long and I want user to able scroll it, if mouse is over the component and wheel is scrolled. I do not find any OnMouseWheel, OnMouseWheelDown or OnMouseWheelUp event for TListView object. How can I

  • How to get selected values (using checkBox) from DataGrid in flex 2012-01-02

    i have a datagrid which is getting values from a XML file (getting this xml file from database using PHP and HTTP request in flex). i have created a checkbox in every row in data grid. and here is my requirement: i want to select tow or three check-b

  • android edittext and multiple checkboxes 2012-04-20

    I need an editText and 10 checkboxes. On android phone I also need to have a scrollview. I mean I need to see the checkboxez in a scroll. How to do that? Can someone post an layout example? --------------Solutions------------- <?xml version="1.0"

  • How can I trigger an itemEditEnd Event in a Flex List when the CheckBox is checked/unchecked? 2009-06-30

    I have a List component that has drop-in CheckBox itemEditor that also serves as the itemRenderer. It displays each item as a simple CheckBox with a label. However, the itemEditEnd Event does not get triggered until I click on something outside of th

  • How to find checkbox value ( checked/unchecked) in iteamreander of data grid ? 2009-07-04

    I have 3 checkboxes for calculating amount purpose. I used Datagrid within datgrid used <mx:DataGrid> <mx:itemRenderer> <mx:Component> <mx:CheckBox id=mycheckbox change="calc()"/> </mx:Component> </mx:itemRenderer>

  • UITableView doesn't scroll when number of items is less than scrollable limit 2009-09-07

    I've a UITableView and I populate data from a service. When the number of rows is higher than what could be displayed on the screen, I'm able to scroll the table. But when it's less (say 1 or 2), I'm unable to scroll (in the sense, the bouce effect d

  • Is it possible to change the font size of TListView groups? 2009-12-11

    Starting with Delphi 2009, the TListView component now offers the possibility to show items grouped using the Groups feature. Is it possible to change the font size of just the groups header text? By default it uses the same font and size as the rest

  • Error - while trying to select the checkbox, when a row is selected in the datagrid 2010-01-06

    I want my checkbox -- which is in a datagrid, to be selected when the row of the datagrid is selected. And for this I wrote the following code: <mx:DataGrid id="dg_trashContent" allowMultipleSelection="true" verticalGridLines="true" dataProvider="

  • Checkbox selected field from xml problem 2010-02-09

    I am trying to set the selected value of a checkbox from a dataprovider (an xml file). <mx:DataGridColumn width="75" headerText="show/hide" dataField="@hidden"> <mx:itemRenderer> <mx:Component> <mx:CheckBox selected="{[email protected]

  • TListView performance issues 2010-08-13

    I tried to use a TListView component to display rather large data lists (like 4000 rows large), and creating the list is incredibly slow - it takes something like 2-3 secs, which makes the UI all laggy and close to unusable. I fill the TListView.Item

Copyright (C) pcaskme.com, All Rights Reserved.

processed in 0.478 (s). 13 q(s)