Drawing a listBox

Hi group, I was able to do several things with the listbox. Now, I’d like to be able to draw it, with a code like:

“Calendario is a name of ListBox”
Dim i as integer
Dim x as integer
Dim y as integer
Dim ContaGiorni as integer

ContaGiorni=0
y=0

While y <= 6 And ContaGiorni <= 6
x = 0
Calendario.Row = y + 1
While x <= 6 And ContaGiorni <= 6
Calendario.Col = x + 1
calendario.text = Contagiorni
ContaGiorni = ContaGiorni + 1
x = x + 1
Wend
y = y + 1
Wend

obviously, I find it difficult to convert to Xojo language, can you help me? Thanks.

Again, the documentation spells out everything you want. Now granted, ListBox contains lots of properties/methods/events, so it’s a lot to digest, but I recommend reading through it all to get better aquainted with it. Usually, something you read will spark an idea you hadn’t thought of.

So it looks like what you’re wanting to do is fill the cells with an incrementing number (which is not “drawing”, that’s another feature/function). Note that you usually define the number of columns in the Layout editor and then add rows in code. But both can be done either way if needed.
Some simple examples of the usual way are below.

(use the “preformatted text” option when posting actual code here - select the text and click the </> toolbar button)

//the following assumes the listbox is already configured with 7 columns (0-6),
//but is currently empty (contains no rows)
Dim ContaGiorni as Integer = 1
For r As Integer = 0 To 6
  Calendario.AddRow() //you could include all the row's values here
  For c As Integer = 0 To Calendario.LastColumnIndex
    Calendario.CellValueAt(r, c) = ContaGiorni.ToString
    ContaGiorni = ContaGiorni + 1
  Next
Next

Note that cells of a ListBox can only accept a string, so anything else has to be converted first (and converted back if reading the cells).

Here is another way where the ListBox already contains data:

//the following assumes the listbox already contains all the rows & columns needed
//so it just replaces the contents of all cells
Dim ContaGiorni as Integer = 1
For r As Integer = 0 To Calendario.LastRowIndex
  For c As Integer = 0 To Calendario.LastColumnIndex
    Calendario.CellValueAt(r, c) = ContaGiorni.ToString
    ContaGiorni = ContaGiorni + 1
  Next
Next

Convert To ?

What languages did you use before ?

FWIW there ARE other dat pickers available already that you can / could customize a lot or than the built in one
you might find one in one of the GitHub repositories

Or something like

Thanks for your patience, I am trying to learn this new language, but I am not a programmer by profession. The things I have to do are few, I have already managed to connect to an access database, read, write, edit, delete … and everything from scratch. I have a lot to learn. I understand your listing, but an error returns to me and I don’t understand what it could be due to.

i recived an error on this rows.
Calendario.CellValueAt(r, c) = ContaGiorni.ToString in CellValueAt

It was just an example, I need to figure out how to populate a ListBox with coordinates (X, Y) …

It could be helpful for us, and that way we can help you better, if you tell us the error you are seeing. It could be a screenshot.
Also version of Xojo.

My guess is that you are using Xojo 2022r1.1
And the ListBox is a DesktopListbox
image

and you copied the above code and run, getting this:
image

below you can see the error:
image

you can go to the documentation for DesktopListbox and you will see that there is no CellValueAt and now is called CellTextAt
https://documentation.xojo.com/api/user_interface/desktop/desktoplistbox.html#desktoplistbox

Hope this helps.

Edit: after changing CellValueAt to CellTextAt the result is:
image

One way to see what might be right is to put your cursor after Calendario.
Press return to push the rest of the line to the next row
Move your cursor back to after the dot after Calendario.
Press Tab
that is ALL the methods that the listbox has
You will see there is no CellValueAt

But CellTextAt seems similar
try that

I created a layout like

I added the buttons. Pressed event and in there I put

Sub Pressed() Handles Pressed
  // make sure we have 7 columns
  Calendario.ColumnCount = 7
  // a calendar needs at most 6 week
  For r As Integer = 1 To 6
    Calendario.AddRow( Array("", "", "", "", "", "", "") )
  Next r
  
  //the following assumes the listbox already contains all the rows & columns needed
  //so it just replaces the contents of all cells
  Dim ContaGiorni As Integer = 1
  For r As Integer = 0 To Calendario.LastRowIndex
    For c As Integer = 0 To Calendario.LastColumnIndex
      Calendario.CellTextAt(r, c) = ContaGiorni.ToString
      ContaGiorni = ContaGiorni + 1
    Next
  Next
End Sub

What you’ll notice is the number 1 is NOT on “the first day of the month” :slight_smile:

Hi Npalardy, of course you were right about everything. I tried to read the info of the ListBox, but not understanding how it works well I had difficulty understanding the differences between the old versions and the new one, by chance, I was trying .CellTextAt.
I also wanted to thank you for the practical example you wrote me about my example, it’s perfect and I understand how it works. As for the rows, I thought there was something like in VB6 of the type Calendar.RowCount = 5 … but instead I have to add them with the Addrow command.

LOL… so much for API2 making it EASIER for newer users

From what I understand CellValueAt is API2 but new Desktop controls use CellTextAt (API2 Final?).

Api 2.1 ?
its a mess