Announcement

Collapse

Looking for a User App or Add-On built by the NinjaTrader community?

Visit NinjaTrader EcoSystem and our free User App Share!

Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
See more
See less

Partner 728x90

Collapse

NTTabPage.GetHeaderPart appending number to tab's

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    NTTabPage.GetHeaderPart appending number to tab's

    I have created a new window for my Addon with tabs. I have done this before many times but this one instance is having unexpected behavior.

    I have override GetHeaderPart to return the name of the tab I want. NinjaTrader is appending a number after the tab name. I can't figure out how the name of the tab is having a number appended to it.

    Code:
    protected override string MyTabPage.GetHeaderPart(string variable)
    {
        if(string.IsNullOrEmpty(tabCaption))
        {
            return "No Name";
        }
        return tabCaption;
    }
    
    ...
    
    public void MyAddonWindow.AddTab(MyTabPage tabPage)
    {
        tabControl.AddNTTabPage(tabPage);
    }
    The tab names are all unique in the window so its not a situation tabCaption is set to the same value. tabCaption is a member variable in my derived class that I assign in the constructor.

    The tabs are being added in code after the window is created but before it is shown.

    Code:
    var myNewWindow = new MyAddonWindow();
    
    myNewWindow.AddTab(new MyTabPage("Some Tab"));
    myNewWindow.AddTab(new MyTabPage("A different Tab"));
    
    myNewWindow.Show();
    I'll get "Some Tab 11" and then "A different Tab 59" for the actual tab names.
    Last edited by ntbone; 05-16-2023, 11:39 PM.

    #2
    Hello, thanks for writing in. The addon framework example overrides GetHeaderPart and does not do this. You will need to reference this example to see what your script is doing differently in this instance:
    Chris L.NinjaTrader Customer Service

    Comment


      #3
      I have already referenced that example, and the numerous other places in my own code where I override GetHeaderPart and return the name of the tab. I have debugged the string returned by GetHeaderPart and it definitely isn't adding any number to the string there. The only difference between this situation and the sample or my other addons is that this one adds tab pages in code as I pointed out above.

      Comment


        #4
        Hi, do you have a reduced test script that I can test on my PC?
        Chris L.NinjaTrader Customer Service

        Comment


          #5
          See attached. Needs to be put in the Addon's folder. Should be self contained. Demonstrates the problem.
          Attached Files

          Comment


            #6
            Hi, thanks for posting this. There was something about how you were passing in the string that was causing the number to be appended. I was able to fix it by changing the constructor of TestAddTabTabPage to this:

            public TestAddTabTabPage(string tabCaption)
            {
            TabName = tabCaption;
            }​
            Chris L.NinjaTrader Customer Service

            Comment


              #7
              That solution might fix it but that doesn't explain why returning it as my code provides appends a # to the name. The member variable "tabCaption" is readonly and is assigned the parameter passed in. It is then returned by "GetHeaderPart". NinjaTrader is adding a # when it calls GetHeaderPart. What is number and why is it adding it?

              Comment


                #8
                Hi, the Addon framework example is not doing this. Unfortunately, I am not going to be able to look through your code anymore to find the difference between your test script and the example that I linked in a previous post. You will need to compare and contrast your test code with the addon framework example to find the difference here. Additionally, your GetHeaderPart() is not using the "variable" to determine what the tab name should be so setting the tab name is a sound solution for this instance.

                Kind regards,
                -ChrisL
                Chris L.NinjaTrader Customer Service

                Comment


                  #9
                  The code I created is pretty simple. It stores the desired tab name as a member variable and uses it as a return to GetHeaderPart. If at some point I wanted to optionally use the variable, I wouldn't be able to. I don't have access to NinjaTrader's internal code and its NinjaTrader's internal code that is adding the number. The string is read only and being returned directly so there's no where anywhere in my code for a # to be added. The code I presented couldn't be any simpler, aside from the necessary code to add a menu item to launch the addon window.

                  Comment


                    #10
                    Hi, the Addon Framework example I posted is not doing this. Please use this as an exemplar for all addons tab naming conventions going forward.
                    Chris L.NinjaTrader Customer Service

                    Comment


                      #11
                      For those who, like me, end up confused by the behavior of GetHeaderPart adding a number
                      • If you use the code I shared above, but only have 1 Tab, no number will be added.
                      • If you add more then one tab, the numbers will be added and its undetermined what number each will be assigned.
                      • GetHeaderPart is called for a list of predefined variables that can be swapped out. See Tab Name Variables
                      • If you only use "@FUNCTION" as seen here you will still get non-sequential numbers appended to all your tabs. You must add something after "@FUNCTION". A single space is sufficient but adding other things like "@INSTRUMENT" or any of the other variables will also work.
                      To get my code to work as expected

                      Code:
                      public MyTabPage()
                      {
                          TabName = "@FUNCTION ";  // insert here whatever full pattern you'd like the tab name to have.  If you don't plan to use any variables
                                                  // at all, you could just assign the tab name here.  However, you can then have multiple tabs with the exact same
                                                  // name. If you want your tab names to increment for duplicates "My Tab", "My Tab 1", "My Tab 2" then use the  
                                                  // "@FUNCTION "
                                                  // ** The extra space is important. Without it your tabs will all get numbers and they won't be sequential.  **
                      }
                      
                      protected override string MyTabPage.GetHeaderPart(string variable)
                      {
                          if(variable == "@FUNCTION")
                          {
                              if(string.IsNullOrEmpty(tabCaption))
                              {
                                  return "No Name";
                              }
                              return tabCaption;
                          }
                          return variable;
                      }
                      
                      ...
                      
                      public void MyAddonWindow.AddTab(MyTabPage tabPage)
                      {
                          tabControl.AddNTTabPage(tabPage);
                      }
                      BUG: Using "@FUNCTION" similar to the sample referenced in responses to my post still results in the numbers being appended to the tabs and not sequentially.
                      Last edited by ntbone; 05-18-2023, 07:01 PM.

                      Comment

                      Latest Posts

                      Collapse

                      Topics Statistics Last Post
                      Started by JoMoon2024, Today, 06:56 AM
                      0 responses
                      6 views
                      0 likes
                      Last Post JoMoon2024  
                      Started by Haiasi, 04-25-2024, 06:53 PM
                      2 responses
                      19 views
                      0 likes
                      Last Post Massinisa  
                      Started by Creamers, Today, 05:32 AM
                      0 responses
                      6 views
                      0 likes
                      Last Post Creamers  
                      Started by Segwin, 05-07-2018, 02:15 PM
                      12 responses
                      1,786 views
                      0 likes
                      Last Post Leafcutter  
                      Started by poplagelu, Today, 05:00 AM
                      0 responses
                      3 views
                      0 likes
                      Last Post poplagelu  
                      Working...
                      X