CheckListBox Items

Components on the Raize Lists palette: list boxes, check lists, combo boxes, tree views, list views, grids, etc.

CheckListBox Items

Postby Bazzer747 » Mon Apr 16, 2018 1:56 pm

Hi
I want to use the TRzListBox to add several items for selection by the User. What I want to display is a checkbox alongside a name then a single character (which indicate a status for that name). I would want these in two groups.

Can you give and example of how you would do this?

I can use the Add( string ) property to get just the single column of names, but how do I get the second column of characters? And also how do you add different items to each group (much like it shows in your demo project)?
Bazzer747
 
Posts: 23
Joined:
Tue Jan 12, 2016 6:05 am

Re: CheckListBox Items

Postby Raize Support » Tue Apr 17, 2018 1:43 pm

Hi,

I believe the following code sample is close to what you are describing. To add the groups, the AddGroup method is used. This method is essentially the same as the Add method, but automatically prefixes the string to be added with the GroupPrefix property inherited from the base TRzListBox. Then to add the items, AddItemToGroup method is used to simplify the process. However, if you are adding the items and groups in order, the AddItemToGroup could be replaced with just calls to the Add method. To get the additional columns, a tab character (#9) is inserted at column breaks. The TabStopsMode is set to tsmAutomatic so that all the columns line up nicely.

Code: Select all
  RzCheckList1.TabStopsMode := tsmAutomatic;
  RzCheckList1.AddGroup( 'Group 1' );
  RzCheckList1.AddItemToGroup( 0, 'Luke'#9'L' );
  RzCheckList1.AddItemToGroup( 0, 'Anakin'#9'A' );
  RzCheckList1.AddItemToGroup( 0, 'Yoda'#9'Y' );
  RzCheckList1.AddGroup( 'Group 2' );
  RzCheckList1.AddItemToGroup( 1, 'Han'#9'H' );
  RzCheckList1.AddItemToGroup( 1, 'Lando'#9'L' );
  RzCheckList1.AddItemToGroup( 1, 'Chewbacca'#9'C' );


Ray
Raize Software Support
Raize Software
http://www.raize.com
Raize Support
 
Posts: 613
Joined:
Fri Mar 25, 2011 9:04 pm

Re: CheckListBox Items

Postby Bazzer747 » Fri Apr 20, 2018 12:12 pm

Ray
Many thanks.
I'm populating from a table with usual loop through all it's records adding to the listbox:
with dm.fdqTeamPositions do
begin
First;
while NOT EOF do
begin
cName:= FieldByName( 'FULLNAME').AsString;
clConfirmations.AddItemToGroup( 0, cName #9'P' );
Next;
end;
end;
However, above throws an error 'expecting ')' but string constant found. Tried QuotedStr( cName ), but same.
Otherwise, works a treat.
Bazzer747
 
Posts: 23
Joined:
Tue Jan 12, 2016 6:05 am

Re: CheckListBox Items

Postby Raize Support » Fri Apr 20, 2018 1:14 pm

Hi,

You can use #9 as a literal character and embedded in a literal string such as:
'Hello'#9'World'

However, when you are using a variable for one of the substrings, you need to use the + to concatenate. For example,

clConfirmations.AddItemToGroup( 0, cName + #9'P' );

Ray
Raize Software Support
Raize Software
http://www.raize.com
Raize Support
 
Posts: 613
Joined:
Fri Mar 25, 2011 9:04 pm

Re: CheckListBox Items

Postby Bazzer747 » Sun Apr 22, 2018 1:34 pm

Once again, thanks.
Bazzer747
 
Posts: 23
Joined:
Tue Jan 12, 2016 6:05 am

Re: CheckListBox Items

Postby Bazzer747 » Mon Apr 23, 2018 8:06 am

One last thing, if I can, Ray ...
Whilst I populate the checklistbox I want to indicate whether the item should be checked or unchecked, depending on the value of a field in the table.

Can I do this at the same time as I AddItemToGroup?
Bazzer747
 
Posts: 23
Joined:
Tue Jan 12, 2016 6:05 am

Re: CheckListBox Items

Postby Raize Support » Mon Apr 23, 2018 4:21 pm

Hi,

You cannot set the check state directly in the call to AddItemToGroup. However, you can use the AddEx call to do this--although it does not allow you to specify the group. The easiest is to just add the item to the group and then set the check state as such:

Code: Select all
  Idx := RzCheckList1.AddItemToGroup( 0, 'Test' );
  RzCheckList1.ItemChecked[ Idx ] := True;


Ray
Raize Software Support
Raize Software
http://www.raize.com
Raize Support
 
Posts: 613
Joined:
Fri Mar 25, 2011 9:04 pm

Re: CheckListBox Items

Postby Bazzer747 » Tue Apr 24, 2018 3:52 am

Ray,
Seems to work but I have an oddity. Here's my code (clConfirmations being the checklist):

with dm.fdqTeamsAll do
begin
First; while NOT EOF do
begin
if ( FieldByName( 'Event' ).AsString = gvEvent ) then
begin
Idx:= clConfirmations.AddItemToGroup( 0, FieldByName( 'PlayerA').AsString ) ;
clConfirmations.ItemChecked[ Idx ]:= False;
Idx:= clConfirmations.AddItemToGroup( 0, FieldByName( 'PlayerB').AsString ) ;
clConfirmations.ItemChecked[ Idx ]:= True;
end;
Next;
end;
Eventually I'll set True or False from the table field, as it will change over time. With above setting, though, all items show unchecked. If I make PlayerA 'True' and PlayerB 'False' all is correct.

I'll split the loop out to add individual items rather than adding two at once and see if that sorts it out.
Bazzer747
 
Posts: 23
Joined:
Tue Jan 12, 2016 6:05 am

Re: CheckListBox Items

Postby Bazzer747 » Tue Apr 24, 2018 3:58 am

Ray
Forget last reply, my code was poor. Everything works as expected having tested all variations, so thanks for helping me along.
Lesson: must check logic of code through debugger before making assumptions!
Bazzer747
 
Posts: 23
Joined:
Tue Jan 12, 2016 6:05 am

Re: CheckListBox Items

Postby Raize Support » Tue Apr 24, 2018 8:01 pm

No problem. Glad to hear you tracked down the issue

Ray
Raize Software Support
Raize Software
http://www.raize.com
Raize Support
 
Posts: 613
Joined:
Fri Mar 25, 2011 9:04 pm


Return to Lists

Who is online

Users browsing this forum: No registered users and 1 guest

cron