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
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
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 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
and you copied the above code and run, getting this:
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
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
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.