Difference between revisions of "TCheckListBox"

From Lazarus wiki
Jump to navigationJump to search
(Some details how to use TCheckListBox)
 
(3 intermediate revisions by 2 users not shown)
Line 7: Line 7:
 
== Usage ==
 
== Usage ==
  
Think of TCheckListBox as having two parts, the strings shown to the right and the checkboxes to the left. The strings are typically descriptions of what the user is selecting if they click a checkbox. The strings may be loaded individually using (eg) -
+
Think of TCheckListBox as having two parts, the strings in a [[TListBox]] shown to the right and the checkboxes to the left. The strings are typically descriptions of what the user is selecting if they click a checkbox. The strings may be loaded individually using (eg) -
  
 
<syntaxhighlight lang="pascal">CheckListBox1.AddItem('Line One', Nil);
 
<syntaxhighlight lang="pascal">CheckListBox1.AddItem('Line One', Nil);
Line 39: Line 39:
 
         if CheckListBox1.Checked[I] then DebugLn('Checked Item ' + CheckListBox1.Items[I]);</syntaxhighlight>
 
         if CheckListBox1.Checked[I] then DebugLn('Checked Item ' + CheckListBox1.Items[I]);</syntaxhighlight>
  
 +
==Comparison with TCheckGroup==
  
 +
There is a similar control named TCheckGroup on Standard component pallette tab. The differences are
  
 +
1) The items within TCheckGroup are spaced evenly, while TCheckListBox allows scroll down.
 +
 +
2) TCheckListBox has property of AllowGrayed.
  
 
==See also==
 
==See also==

Latest revision as of 02:10, 4 April 2022

English (en) suomi (fi) français (fr) polski (pl) русский (ru)

A TCheckListBox tchecklistbox.png is a component that shows a (scrollable) list of checkboxes where user can make multiple selections. It is available from the Additional tab of the Component Palette.

CheckListBoxDemo.png

Usage

Think of TCheckListBox as having two parts, the strings in a TListBox shown to the right and the checkboxes to the left. The strings are typically descriptions of what the user is selecting if they click a checkbox. The strings may be loaded individually using (eg) -

CheckListBox1.AddItem('Line One', Nil);
CheckListBox1.AddItem('Line Two', Nil);

Or you can assign an existing string list filled elsewhere -

CheckListBox1.Items.Assign(MyStringList);

Its a good idea to then put the checkboxes in a know state -

    for I := 0 to CheckListBox1.Count-1 do
        CheckListBox1.Checked[I] := False;

TCheckListBox allows the user to select as many or as few checkboxes as they like. Use the OnItemClick event to force no more than one -

procedure TNoteBookPick.CheckListBox1ItemClick(Sender: TObject; Index: integer);
var
	I : integer;
begin
    if (Sender as TCheckListBox).Checked[Index] then begin
        for I := 0 to CheckListBox1.Count -1 do
            CheckListBox1.Checked[I] := False;
        CheckListBox1.Checked[Index] := True;
    end;
end;

To read the Check Boxes when (eg) the user has finished -

    for I := 0 to CheckListBox1.Count -1 do
        if CheckListBox1.Checked[I] then DebugLn('Checked Item ' + CheckListBox1.Items[I]);

Comparison with TCheckGroup

There is a similar control named TCheckGroup on Standard component pallette tab. The differences are

1) The items within TCheckGroup are spaced evenly, while TCheckListBox allows scroll down.

2) TCheckListBox has property of AllowGrayed.

See also


LCL Components
Component Tab Components
Standard TMainMenu • TPopupMenu • TButton • TLabel • TEdit • TMemo • TToggleBox • TCheckBox • TRadioButton • TListBox • TComboBox • TScrollBar • TGroupBox • TRadioGroup • TCheckGroup • TPanel • TFrame • TActionList
Additional TBitBtn • TSpeedButton • TStaticText • TImage • TShape • TBevel • TPaintBox • TNotebook • TLabeledEdit • TSplitter • TTrayIcon • TControlBar • TFlowPanel • TMaskEdit • TCheckListBox • TScrollBox • TApplicationProperties • TStringGrid • TDrawGrid • TPairSplitter • TColorBox • TColorListBox • TValueListEditor
Common Controls TTrackBar • TProgressBar • TTreeView • TListView • TStatusBar • TToolBar • TCoolBar • TUpDown • TPageControl • TTabControl • THeaderControl • TImageList • TPopupNotifier • TDateTimePicker
Dialogs TOpenDialog • TSaveDialog • TSelectDirectoryDialog • TColorDialog • TFontDialog • TFindDialog • TReplaceDialog • TTaskDialog • TOpenPictureDialog • TSavePictureDialog • TCalendarDialog • TCalculatorDialog • TPrinterSetupDialog • TPrintDialog • TPageSetupDialog
Data Controls TDBNavigator • TDBText • TDBEdit • TDBMemo • TDBImage • TDBListBox • TDBLookupListBox • TDBComboBox • TDBLookupComboBox • TDBCheckBox • TDBRadioGroup • TDBCalendar • TDBGroupBox • TDBGrid • TDBDateTimePicker
Data Access TDataSource • TCSVDataSet • TSdfDataSet • TBufDataset • TFixedFormatDataSet • TDbf • TMemDataset
System TTimer • TIdleTimer • TLazComponentQueue • THTMLHelpDatabase • THTMLBrowserHelpViewer • TAsyncProcess • TProcessUTF8 • TProcess • TSimpleIPCClient • TSimpleIPCServer • TXMLConfig • TEventLog • TServiceManager • TCHMHelpDatabase • TLHelpConnector
Misc TColorButton • TSpinEdit • TFloatSpinEdit • TArrow • TCalendar • TEditButton • TFileNameEdit • TDirectoryEdit • TDateEdit • TTimeEdit • TCalcEdit • TFileListBox • TFilterComboBox • TComboBoxEx • TCheckComboBox • TButtonPanel • TShellTreeView • TShellListView • TXMLPropStorage • TINIPropStorage • TJSONPropStorage • TIDEDialogLayoutStorage • TMRUManager • TStrHolder
LazControls TCheckBoxThemed • TDividerBevel • TExtendedNotebook • TListFilterEdit • TListViewFilterEdit • TLvlGraphControl • TShortPathEdit • TSpinEditEx • TFloatSpinEditEx • TTreeFilterEdit • TExtendedTabControl •
RTTI TTIEdit • TTIComboBox • TTIButton • TTICheckBox • TTILabel • TTIGroupBox • TTIRadioGroup • TTICheckGroup • TTICheckListBox • TTIListBox • TTIMemo • TTICalendar • TTIImage • TTIFloatSpinEdit • TTISpinEdit • TTITrackBar • TTIProgressBar • TTIMaskEdit • TTIColorButton • TMultiPropertyLink • TTIPropertyGrid • TTIGrid
SQLdb TSQLQuery • TSQLTransaction • TSQLScript • TSQLConnector • TMSSQLConnection • TSybaseConnection • TPQConnection • TPQTEventMonitor • TOracleConnection • TODBCConnection • TMySQL40Connection • TMySQL41Connection • TMySQL50Connection • TMySQL51Connection • TMySQL55Connection • TMySQL56Connection • TMySQL57Connection • TSQLite3Connection • TIBConnection • TFBAdmin • TFBEventMonitor • TSQLDBLibraryLoader
Pascal Script TPSScript • TPSScriptDebugger • TPSDllPlugin • TPSImport_Classes • TPSImport_DateUtils • TPSImport_ComObj • TPSImport_DB • TPSImport_Forms • TPSImport_Controls • TPSImport_StdCtrls • TPSCustomPlugin
SynEdit TSynEdit • TSynCompletion • TSynAutoComplete • TSynMacroRecorder • TSynExporterHTML • TSynPluginSyncroEdit • TSynPasSyn • TSynFreePascalSyn • TSynCppSyn • TSynJavaSyn • TSynPerlSyn • TSynHTMLSyn • TSynXMLSyn • TSynLFMSyn • TSynDiffSyn • TSynUNIXShellScriptSyn • TSynCssSyn • TSynPHPSyn • TSynTeXSyn • TSynSQLSyn • TSynPythonSyn • TSynVBSyn • TSynAnySyn • TSynMultiSyn • TSynBatSyn • TSynIniSyn • TSynPoSyn
Chart TChart • TListChartSource • TRandomChartSource • TUserDefinedChartSource • TCalculatedChartSource • TDbChartSource • TChartToolset • TChartAxisTransformations • TChartStyles • TChartLegendPanel • TChartNavScrollBar • TChartNavPanel • TIntervalChartSource • TDateTimeIntervalChartSource • TChartListBox • TChartExtentLink • TChartImageList
IPro TIpFileDataProvider • TIpHtmlDataProvider • TIpHttpDataProvider • TIpHtmlPanel
Virtual Controls TVirtualDrawTree • TVirtualStringTree • TVTHeaderPopupMenu