Add Checkbox to Listbox in REALbasic line

In this tutorial we will learn how can we add a Checkbox to Listbox Control in REALbasic. We will also learn how can we check the status of Checkbox in Listbox row. Watch it, learn it, enjoy it!

Add Checkbox to Listbox

Place a Listbox on Window1 Class and enter in this control some data in Listbox1 Property InitalValue. Now can you add for example to Listbox1 Sub Open () a code to display a Checkbox in each row available in column 0.

1
me.ColumnType(0) = ListBox1.TypeCheckBox // ColumnType(column number)

Checkbox status in Listbox Control

In this part we will count how many Checkboxes are checked in our Listbox Control. To do this we will add to Window1 a PushButton control and by double clicking on it we will go to Code Editor PushButton1 Sub Action (). Here we enter this code.

1
2
3
4
5
6
7
8
9
10
11
12
13
Dim i, c As Integer
 
c = 0
 
for i = 0 to ListBox1.ListCount-1 // check every cell in Listbox control
 
  if ListBox1.CellCheck(i,0) = true then // if checked state = true
    c = c + 1
  end if
 
next i
 
MsgBox "You selected " + Str(c) + " items" //display how many items are checked

ListBox.CellType

We can also beyond TypeCheckBox add some other settings to Lisbox Cell. Sets the type of the passed cell. Row and Column are zero-based. Use the following class constants to set the CellType. TypeDefault (0): Default, same as its column type; TypeNormal (1): Normal, not editable; TypeCheckBox (2): Add checkbox; TypeEditable (3): Inline editable.

1
Listbox1.CellType(1,1) = ListBox1.TypeEditable

The values of CellType > 0 override ColumnType. For example, if ColumnType is 2, but a cell in the column has CellType set to 1, the cell will be normal.

Author: Jakub Pawlak

I'm interested in all. Currently working on the development of TUTSPOLIS and I hope that in near feature the project will be successful.

3 Responses to “Add Checkbox to Listbox in REALbasic”

  1. Arjun says:

    Good information. Can you please give other type as well. That will be useful for newbie, just like me. :)

  2. Jakub Pawlak says:

    There will be more tutorials for fresh users :) Now I’m making a simple tutorial about creating a download manager in REALbasic with progressbar etc.

  3. Cory says:

    excellent, I am moving over from VB6 and I could not find any listing that list the data types for these controls… This help out a lot.

Leave a Reply

Copyrights (c) TUTSPOLIS | Powered by Wordpress MU | Inspired at Elegant Themes designed by qbap (HTML5 & CSS3)