gettingstarted
[Top] [All Lists]

ListBox: Second Part - Piece 1

To: Getting Started <gettingstarted at lists dot realsoftware dot com>
Subject: ListBox: Second Part - Piece 1
From: Nils Frisch <n dot f dot forumbox at wanadoo dot fr>
Date: Wed, 27 Oct 2004 17:15:17 +0200
Delivered-to: gettingstarted at lists dot realsoftware dot com
France,
Toulouse,
Wednesday, October, 27th, 2004,
4:52 pm.


Hello World,


In one of my previous email, I tried to learn you how to play with the basic
(i.e. "The must have to know") properties (i.e. state), methods (i.e.
behaviors) and event handlers of "ListBox" controls. It was the first part,
that is to say the first important step.
Since some people would like to know the rest of the story, this email
treats the second part: multiple column "ListBox" controls and cell
management.

Note
My post is too long (greater than 20 KB) to be treated by the mailing list.
I divided it into two piece.
(These kind of post from me is exceptional, sorry Administrator.)

In this post, while I use some idea developped in the previous post, I try
to begin from scratch.
That allows me to show you how the concepts are independents.

The group of properties to keep in mind today is composed by:

    - CellType
    - ColumnCount
    - ColumnType

The methods to know are:

    - Cell

And the event handlers are:

    - CellAction
    - CellClick

There are more other properties, methods and event handlers to discover, but
I prefer to treat them in another post (if you want it, let's me know): a
bonus part, like DVD-Video. :)
Small moves to learn better and more !

Now some code.

    - Launch REALbasic.
A new project window titled "Untitled" opens with three items named
"Window1", "MenuBar1" and "App". These items are classes (but you can call
them blueprint of objects or family, categories).

    - Double-click the "Window1" class (or item if you prefer this term) to
open it.
A new window titled "Untitled" (yes, named like the project window, so don't
be puzzled: they are two different entities) appears on screen with an empty
content area.

    - From the object floating window of REALbasic, drag and drop an one
based column "ListBox" control to the content of the "Window1" window.
A new "ListBox" control appears on screen with a blank area and a scroll bar
on the right side. By default, the name of this "ListBox" is "ListBox1"
(look at the properties floating window, for checking).

    - Double-click on the new "ListBox" control named "ListBox1".
A new window appears titled "Window1 Source Code", that we also call the
code editor window, with a kind of browser on the left side of this window
and a large area for editing on the right side.
By default REALbasic selects the "Change" event handler of the "ListBox"
called "ListBox1".

    - Select the "Open" event handler of the "ListBox" control named
"ListBox1".
The content on the right side of the editor window change to display this
code:

    Sub Open()

    End Sub

    - Insert the following code:

    Sub Open()
        Me.AddRow "My first line"
        Me.AddRow "My second line"
        Me.AddRow "My third line"
    End Sub

    - To finish, run your application by choosing the "Debug -> Run"
Menu command.
(Don't close the code editor window, since we will need it later.)

Now, our application display a filled "ListBox" control and we can start to
play around.
(If you read my previous post, until here, nothing is new for you.)

You must understand we are working with a "ListBox" control which contains
only one column. This column is called 0. Sorry, I wanted to say "numbered
0". :) In addition, you must keep in mind that the first row of the
"ListBox" is always numbered 0.
(Again, you already know that if you read my previous post.)

New step:

    - Quit your application to come back to REALbasic.
The code editor window named "Window1 Source Code" is in front of your
screen.

    - Close this window.
The window that represent the content of the "Window1" window appears.

    - From the object floating window of REALbasic, drag and drop a
"PushButton" control to the window that represent the content of the
"Window1" window.
A "PushButton" control appears labeled "Untitled".
The thru name of this "PushButton" is "PushButton1" (look at its properties
floating window).

    - Double-click on this "PushButton" control to open its code editor
window.
The code editor window titled "Window1 Source Code" appears.
By default, the "Action" event handler of your "PushButton" control called
"PushButton1" is selected.

    - Type the following code in the "Action" event handler of our
"PushButton":

    Sub Action()
        ListBox1.Cell(0, 1) = "Updated !!"
    End Sub

    - Run your application by stroking the rabbit (i.e. "Debug -> Run" menu
command).
Your application is launched and the main window of your application appears
with two controls: a filled "ListBox" control and a "PushButton" control
labeled "Untitled".

    - Press the "PuschButton" control while you are looking at your
"ListBox" control.
The second line (the row technically numbered 1) of your "ListBox" control
has changed from "My second line" to "Updated !!".

A little more about the "Cell" method (yes, it's a method).

    - Quit your application to come back to REALbasic.
The "Window1 Source Code" appears in front, again.

    - Erase the code you previously typed in from the content of the
"Action" event handler's body.

    - Type the following code in the "Action" event handler of our
"PushButton" control:

    Sub Action()
        MsgBox ListBox1.Cell(0, 1)
    End Sub

    - Run you application by choosing the "Debug -> Run" menu command.
Our window appears with our "ListBox" and "PushButton" controls... again.

    - Press the "PushButton" control.
A dialog box window appears with "My second line" as message.

So, the "ListBox.Cell()" method of "ListBox" controls allow us to read or
write the content of a particular row.

Note:
If you remember it, the "ListBox.List(...)" (replace "..." by an integer
which is an index) allows us to read and write the content of a row.
I remind you its type is "array".

The "ListBox.Cell()" method seems to behave like the "List(...)" property of
the "ListBox". But what is the difference ?
I remind you that "ListBox.List(...)" is a property, not a method. The type
of this property is "array".
"ListBox.Cell()" is a method, not a property.
And most important, with the "ListBox.Cell()" method you are more accurate
since you specify the column number. Here, we deal with the first column,
that is to say the column numbered 0.
The "ListBox.List(...)" property only deal with the first column.

Note:
When I write "foo()" that means a method.
When I write "boo(...)" that means a property. Of course it's precisely an
array variable.
My convention is to help you for avoiding any confusion between a word that
represents a method and a word that represents a property.

Note:
I have just told: 'So, the "ListBox.Cell" method of "ListBox" controls allow
us to read or write the content of a particular row'. Is it correct to say
'... row.' ?
Since the "ListBox.Cell" method ask us to specify the row number but also
the column number, it's more correct to use the word "cell" instead "row".
If I used "row" until now, it's because we worked with one based column
"ListBox" control. But, in fact, a one based column "ListBox" control is a
multiple column "ListBox" control with only one column.

This last note will become clearer when we will play with multiple column
"ListBox" controls.

    - Quit your application to come back to REALbasic.
The "Window1 Source Code" window is in front of your screen, again.

    - Close this code editor window, that is to say "Window1 Source Code".
Now, the window that represents the content of our "Window1" window is in
foreground.

    - Drag and drop a multiple column "ListBox" from the control floating
window to the content of our "Window1" window.
Now, our "Window1" window hosts three controls: two "ListBox" controls a bit
different, and a "PushButton" control.

Note:
The newly added "ListBox" control is called "ListBox2", by default. Look at
the property floating window, for checking.

    - Double-click on the new "ListBox" control, called "ListBox2".
The famous "Window1 Source Code" window opens. And the "Change" event
handler of "ListBox2" is selected.

    - Select the "Open" event handler of "ListBox2".
The right side of the code editor window shows you:

    Sub Open()

    End Sub

    - Write the following code:

    Sub Open()
        Me.AddRow "Cell 0 0"
        Me.Cell(0, 1) = "Cell 0 1"
        Me.AddRow "Cell 1 0"
        Me.Cell(1, 1) = "Cell 1 1"
        Me.AddRow "Cell 2 0"
        Me.Cell(2, 1) = "Cell 2 1"
    End Sub

    - Launch your application by using the "Debug - Run" menu command.
Your application display the same window as before, but there is a new
control: a filled "ListBox" control with two columns.

The new "ListBox" control displays a different content in relation to our
previous one based column "ListBox" control. The content seem to be more
complex.

Like before, we use the "ListBox.AddRow()" method to create new entry (i.e.
row) in the "ListBox" control. When this method is executed, REALbasic
create a new line (i.e. row), composed by two cells. Two cells ? Yes, since
our new "ListBox" control contains more than one column.
The first cell is filled with the parameter (a string) you pass to the
"ListBox.AddRow()" method.
But the "ListBox.AddRow()" method only affects the first cell of the new
line ! So, how to set the content of the second cell of a newly created line
(Note: "line" and "row" are synonyms) ? It's done by the "ListBox.Cell()"
method you learn in the previous steps.

Note:
You can think of "ListBox.AddRow()" as a lazy method... :)

So, this code show you two things:

    - "Cell" is fully illustrated thank to two group of steps: the previous
steps where we used a one based column "ListBox" control, and this last step
where we use a multiple column "ListBox" control. Now you have a two
dimensional point of view of the "ListBox.Cell()" method.

    - To entirely fill in a multiple column "ListBox" control, the strategy
is to execute first "ListBox.AddRow()" and second "ListBox.Cell()". We could
call this the "AddRow/Cell" strategy. Of course, if your "ListBox" has three
column, you will use the "AddRow/Cell/Cell" strategy. And so on.


[End Of Piece 1]


Nils

----
----

P.S.:
- Sorry for the delay.
- Sorry for my English.
I promise you to enhance my English with the time: it's a matter of time.
However, I would be very tolerant if you speak an approximate French. ;-)
Thank you for your patience.

----
----

"On ne voit bien qu'avec le coeur. L'essentiel est invisible pour les yeux."
"We only see well with our hearts. What is truly important is invisible to
our eyes."

Le Petit Prince, Antoine de Saint Exupéry

----
----

"Ce n'est pas l'homme qui doit s'adapter à la machine mais la machine qui
doit répondre aux besoins de l'homme."
"It is not the man who should adapt himself to the machine but the machine
which should meet the needs of the man."

Nils Frisch

----
----

Nils Frisch

Toulouse,
France. 

_______________________________________________
Unsubscribe or switch delivery mode:
<http://www.realsoftware.com/support/listmanager/>

Search the archives of this list here:
<http://www.realsoftware.com/listarchives/lists.html>

<Prev in Thread] Current Thread [Next in Thread>
  • ListBox: Second Part - Piece 1, Nils Frisch <=