Is there a more efficient way to set properties of each tab in a tabstrip?
Posted
#1
(In Topic #1244)
Regular

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.
Posted
Guru

TabPanel1[1].Text = "title"
Accessing the TabPanel like an array accesses each tab independently
Posted
Regular

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
Posted
Regular

Posted
Regular

Posted
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.
Posted
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
Posted
Regular

Code
Public Sub Form_Open()
TabPanel1.Count = 3
EndMaybe 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.
Posted
Regular

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.
Posted
Regular

Posted
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
EndIt 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?
Posted
Regular

Posted
Regular

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
Posted
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.
Posted
Guru

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)
- ' Gambas class file
- ' Name: TabPanel.class
- '' Automatically title tabs in numerical order
- Super.Panel_Arrange
1 guest and 0 members have just viewed this.


