Getting Rowtag from popup menu control on a Page Panel

I seem to be having trouble getting the Rowtag from a Popup menu control that is on a Page Panel. It’s always turns up zero after selecting an item. I’m using this similar code in another method that works fine but it is not a popup menu control on a PagePanel. What am I doing wrong or is there another way to get the RowID from a Popup menu control on a Page Panel?

[code]Dim sql As String
Dim rs As RecordSet
Dim iRowID As Integer
Dim sItemName As String

iRowID = MainWindow.PagePanel1.ppmMenu.RowTag(MainWindow.PagePanel1.ppmMenu.ListIndex).IntegerValue

sItemName = MainWindow.PagePanel1.ppmMenu.ppmmenu.Text
For i As Integer = 0 To MainWindow.PagePanel1.ppmMenu.ListCount -1
If MainWindow.PagePanel1.ppmMenu.RowTag(i) = iRowID Then
sql = "SELECT * FROM MyTables WHERE ID = "+ str( iRowID )
Exit For i
End If
Next

rs = db.SQLSelect(sql)[/code]

If the control is on the same window where you have your code, all you should have to do is reference it by name.

iRowID = ppmMenu.RowTag(ppmMenu.ListIndex)

You don’t even need the .IntegerValue because Xojo identifies the RowTag as an integer value when you assign it to your integer variable. You could even combine your Dim and assignment statements like

Dim iRowID As Integer = ppmMenu.RowTag(ppmMenu.ListIndex)

That code won’t even compile. Is PagePanel1 really a PagePanel control? Or are you talking about a ContainerControl?

Hi Tim

Yes that is a Page Panel with the Container Control on it. Sorry, I forgot to mention the Page Panel it has been a while since I did the layout. On this project I have 4 Container Controls with Page Panel 0 - 3 for each. I saw a few Forum posts about the using extends. I’m trying to get my mind around how to use it with this.

In the keeping it simple principle, you could code the popup menu change event to set a public property of its corresponding container control. Then, reference that property from your main window using the container control object and property name.

For example:
Container control CarContainerControl has a public property named ppmValue as Integer

CarContainerControl has a popup menu named ppmMenu with the change event of that popup as follow:

ppmValue = Me.RowTag(Me.ListIndex)

Then you would reference that property from your main window. If the container control in your main window is named myCarCC then you would reference it with:

myCarCC.ppmValue

Hi Tim L

Sorry that didn’t work. I am by no means an expert yet on Xojo coding. All I know is the Xojo Documentation is Row Tag is a Variant. I may be wrong with this. Their sample code to pass a Variant to an integer has the ).IntegerValue to instruct the Variant to Integer or it figures it out somewhere up stream or by the variable it’s passing to.

Here is a warning the Xojo Docs about Variants: Variant can be dangerous if misused because it automatically converts between data types which can lead to unexpected results. In most cases stick with specific data types or use the Auto data type instead.

Is this an issue with scope because of the Page Panel?

So I think what you are telling me is that I have to make the property iRowID scope Global

[code]Dim sql As String
Dim rs As RecordSet
// Dim iRowID As Integer > Make this Global !!!
Dim sItemName As String

iRowID = MainWindow.PagePanel1.ppmMenu.RowTag(MainWindow.PagePanel1.ppmMenu.ListIndex).IntegerValue

sItemName = MainWindow.PagePanel1.ppmMenu.ppmmenu.Text
For i As Integer = 0 To MainWindow.PagePanel1.ppmMenu.ListCount -1
If MainWindow.PagePanel1.ppmMenu.RowTag(i) = iRowID Then
sql = "SELECT * FROM MyTables WHERE ID = "+ str( iRowID )
Exit For i
End If
Next

rs = db.SQLSelect(sql)[/code]

Isn’t the pagepanel irrelevant here? Don’t you just reference the control as if there was no pagepanel? All the pagepanel does, as far as I can tell, is to group the controls in such a way that one subset or another of them is visible depending on pagepanel.value.

So I don’t see why:

iRowID = ppmMenu.RowTag(ppmMenu.ListIndex)

as posted by Tim Leeland, would be incorrect.

I’ve created a very simple sample app to illustrate this and posted it to Dropbox here. Hopefully this will help clarify.

I made an error in rewriting my summarized code. Sorry Tim for putting you through this it was my bad. I put Page Panel instead the Container Control. Thanks for your help. Your code answer is right for Page Panel but it was suppose to be a Container Control which changes everything.

I started this conversation mentally exhausted and also in frustration. I think I’m going to have to take a break and delete this conversation and start over.

iRowID = MainWindow.ContrControl1.ppmMenu.RowTag(MainWindow.ContrControl1.ppmMenu.ListIndex).IntegerValue

I figured out you were using a container control by the way the conversation went. The sample project I uploaded uses the container control as well as a page panel.

I left the conversation to go to a day job and came back to it and forgot the small details. I’ll look at your sample. Thanks. I went through this simular problem before and solved it. After 6 to 8 months go by it’s easy to forget the details of what was learned.

Comments on the code may help to remember (when I remember to write them).

Hi Tim

I downloaded your example and thank you for your effort to giving that extra help. I made a new distinction from it. I put my Popup Menu Method in a Module to make the issues of Scope easier to deal with. Just some of my old VB6 procedural programming habit’s I have to break.

You put the method directly in the control panel popup menu’s change event. That is something I would have ever thought of doing.

You’re very welcome. I’m glad I could help. Another option that you might want to consider is the use of event definitions with container controls. I changed the previous project to use an event definition instead of a public property. You can find it on Dropbox here.

In summary, you create an event definition at the container control level and raise that event in one way or another inside the container control. Then, where you instantiate the container control, add the event handler and write your code to handle the event like you would any other event.

In this project, i created an event definition, MenuChange, on the container control and raise that event whenever the popup menu, ppmMenu, change event occurs. I also pass the iRowID value to the MenuChange event and eliminate using a public property completely.

Don’t forget to mark this topic as answered if you have no further follow-up questions.