Is there a more efficient way to set properties of each tab in a tabstrip?

Post

Posted
Rating:
#1 (In Topic #1244)
Regular
AndrewZabar is in the usergroup ‘Regular’
Hello,

Trying to get the hang of iterating each tab on a tabstrip and setting properties. Is there a way to address the property of a specific tab without switching to it and then referring to it using .current?
I tried some variations of (0).text, .index(1).text etc. some of the controls in VB6 worked like this so I figured gambas would be able to use the hierarchy like this, but it's not working.
Only way I could get it to work is like this:

Code

 With TabStrip1
    .count = 3
    .index = 0
    .Current.text = "Basic Simple WGET"
    .index = 1
    .Current.text = "Advanced WGET"
    .index = 2
    .Current.text = "Specific Predefined Actions"
    .index = 0
  End With

I would prefer to set the count, then set the text property of each tab dynamically by addressing the tabs' text property of their index, but I cannot find a syntax that works for that.
Online now: No Back to the top

Post

Posted
Rating:
#2
Guru
BruceSteers is in the usergroup ‘Guru’
 Something like

TabPanel1[1].Text = "title"

Accessing the TabPanel like an array accesses each tab independently
Online now: No Back to the top

Post

Posted
Rating:
#3
Avatar
Regular
thatbruce is in the usergroup ‘Regular’
 There a couple of things here.
1. As with many controls, the property values are not set to the IDE values until the control is actually loaded. It is similar for code set property values. So some things depend on when you are trying to setting them.
2. As Bruce said, the "tabs" are best accessed via their index. This applies to both tabpanels and tabstrips. They are in essence an array of the inner thing, and each has its own properties. Thus TabPanel1[1] is a, well a, "panel" rather than a tabpanel (which is a set of "panels"). So you need to interact with the "panel" rather than the tabpanel. That makes perfect sense if you read it after midnight, on a full moon, when Jupiter aligns with Mars and etc. But its true.
b

Online now: No Back to the top

Post

Posted
Rating:
#4
Regular
AndrewZabar is in the usergroup ‘Regular’
 Well that is how I tried it initially but it didn't work. I will try again.
Online now: No Back to the top

Post

Posted
Rating:
#5
Regular
AndrewZabar is in the usergroup ‘Regular’
Okay this time it worked lol. Thank you for the info.
Online now: No Back to the top

Post

Posted
Rating:
#6
Regular
AndrewZabar is in the usergroup ‘Regular’

thatbruce said

There a couple of things here.
1. As with many controls, the property values are not set to the IDE values until the control is actually loaded. It is similar for code set property values. So some things depend on when you are trying to setting them.
2. As Bruce said, the "tabs" are best accessed via their index. This applies to both tabpanels and tabstrips. They are in essence an array of the inner thing, and each has its own properties. Thus TabPanel1[1] is a, well a, "panel" rather than a tabpanel (which is a set of "panels"). So you need to interact with the "panel" rather than the tabpanel. That makes perfect sense if you read it after midnight, on a full moon, when Jupiter aligns with Mars and etc. But its true.
b

Why won't a panel respond to setting the count, the way a tabstrip does?
I made a form with one of each and in the form load, i put for each of them .count = x
x is a number for each of them.
The strip loads and gets the amount of tabs I stated, but the panel does not.
Online now: No Back to the top

Post

Posted
Rating:
#7
Guru
BruceSteers is in the usergroup ‘Guru’

AndrewZabar said

thatbruce said

There a couple of things here.
1. As with many controls, the property values are not set to the IDE values until the control is actually loaded. It is similar for code set property values. So some things depend on when you are trying to setting them.
2. As Bruce said, the "tabs" are best accessed via their index. This applies to both tabpanels and tabstrips. They are in essence an array of the inner thing, and each has its own properties. Thus TabPanel1[1] is a, well a, "panel" rather than a tabpanel (which is a set of "panels"). So you need to interact with the "panel" rather than the tabpanel. That makes perfect sense if you read it after midnight, on a full moon, when Jupiter aligns with Mars and etc. But its true.
b

Why won't a panel respond to setting the count, the way a tabstrip does?
I made a form with one of each and in the form load, i put for each of them .count = x
x is a number for each of them.
The strip loads and gets the amount of tabs I stated, but the panel does not.

I hope you mean TabPanel not Panel.

TabPanel works as expected here.
It must be your code.

post us your example and we'll take a look
Online now: No Back to the top

Post

Posted
Rating:
#8
Regular
AndrewZabar is in the usergroup ‘Regular’
Really simple, to be honest.

Code

Public Sub Form_Open()

  TabPanel1.Count = 3

End

Maybe I need to wait until the control is created? Where then would I put this code? This same code in the Form_Open() sub works perfectly with a tabStrip, just not a tabPanel.
Online now: No Back to the top

Post

Posted
Rating:
#9
Regular
AndrewZabar is in the usergroup ‘Regular’
 I have tried it again and again in slightly varying ways.
It appears to be evident that the tabpanel does not reliably set tab count by using .count, only returns the value. Perhaps only under certain conditions, such as if it had already been modified in the IDE prior to launch.

Could someone test this by creating a plain form, put a tabpanel on it, and in the form load just put MyTabPanel.Count = 3 and run the program. I suspect it will not work, just like mine.
Online now: No Back to the top

Post

Posted
Rating:
#10
Avatar
Regular
thatbruce is in the usergroup ‘Regular’
Try

Code (gambas)

  1. Public Sub Form_Open()
  2.  
  3.   TabPanel1.Count = 4
  4.   For idx As Integer = 0 To 3
  5.     TabPanel1[idx].Text = idx + 1
  6.   Next
  7.  

Online now: No Back to the top

Post

Posted
Rating:
#11
Guru
BruceSteers is in the usergroup ‘Guru’

AndrewZabar said

Really simple, to be honest.

Code

Public Sub Form_Open()

  TabPanel1.Count = 3

End

Maybe I need to wait until the control is created? Where then would I put this code? This same code in the Form_Open() sub works perfectly with a tabStrip, just not a tabPanel.

Andrew Post your code !.

I tried this…

Code

Public Sub Form_Open()

  TabPanel1.Count = 3
  Print TabPanel1.Count

End

It says 3

you posted your example saying "Really simple, to be honest. "

But if that's all the code there is how do you know if you have 3 tabs or not?
So what do you try to do after that does not work for you or makes you think it's not working?
Online now: No Back to the top

Post

Posted
Rating:
#12
Avatar
Regular
thatbruce is in the usergroup ‘Regular’
They are there, they just dont have titles.

Online now: No Back to the top

Post

Posted
Rating:
#13
Avatar
Regular
thatbruce is in the usergroup ‘Regular’
Which in a way actually does characterize this as a bug in the sense of "UI" (which btw is a pseudo-science that I have a great deal of loathing for.)
I have recently (today) been discussing a variant of this on another site.
The user has an expectation that an action results in a visual change and that change should be "expected". Consider this theoretical. There is a tabpanel and a button that (for who knows what reason) that lets the user add another tab. At the moment there will be no visual indication that the new panel exists. What is the users natural reaction? Click it again and again and again … until such time that they raise a bug.
To my way of thinking this is either a poor piece of design or a bad implementation. So now I tend to agree with Andrew. Someone should do something about this!  :?
b

Online now: No Back to the top

Post

Posted
Rating:
#14
Guru
BruceSteers is in the usergroup ‘Guru’

thatbruce said

To my way of thinking this is either a poor piece of design or a bad implementation. So now I tend to agree with Andrew. Someone should do something about this!  :?
b

Bagsy not me!  i'm pestering Ben about enough bugs at present ;)
(and i just moaned at him for dismissing a problem because it didn't exist on his KDE/Manjaro! so i'm on tender ground as it is ;) )


My way of thinking is it's just insufficient coding. (no offense intended) but of course you would give the tabs unique titles.

Implementation is not a simple as you'd think, if you create and remove tabs then you cannot trust the numbering, ie..
TabPanel1.Count=3    ' Creates Tab 1, Tab 2, Tab 3
Then TabPanel1[1].Delete  ' Deletes Tab 2 leaving Tab 1, Tab 3
Then TabPanel1.Count=3  ' would create Tab 3 but Tab 3 already exists. should it renumber them all? or call the new one Tab 2 or Tab 4?

I think It's better left to the programmer to choose.
Online now: No Back to the top

Post

Posted
Rating:
#15
Guru
BruceSteers is in the usergroup ‘Guru’
But then after saying all that….

You could just do this……

Here is a simple TabPanel upgrade that if you save this code as a file called TabPanel.class in your project .src folder it will add a "AutoTitle" property to TabPanel.

attached is a project that shows it at work.

It's really not much code to make a TabPanel auto-title itself :)

Code (gambas)

  1. ' Gambas class file
  2. ' Name: TabPanel.class
  3.  
  4. Public Const _Properties As String = "*,AutoTitle"
  5. '' Automatically title tabs in numerical order
  6. Property AutoTitle As Boolean Use $bAutoTitle
  7.  
  8. Public Sub Panel_Arrange()
  9.  
  10.   If $bAutoTitle Then
  11.     For c As Integer = 1 To Me.Count
  12.       Me[c - 1].Text = "Tab " & c
  13.     Next
  14.   Super.Panel_Arrange
  15.  
  16.  

Attachment
Online now: No Back to the top
1 guest and 0 members have just viewed this.