Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

NT8 Combobox in PropertyGrid

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

    NT8 Combobox in PropertyGrid

    Hi,

    I am trying to implement in the property grid, a dropdown that is populated from List<string>, or string[]. (And yes, I have seen the TypeConverter sample provided by Bertrand). I have tried three different approaches.

    The first approach, similar to that used by Bertrand in his sample, does populate the dropdown but the first line is blank. I have checked the code thoroughly but cannot see the issue Any suggestions, please?

    The second approach uses a class and requires, in the TypeConverter function, an override for StandardValuesCollection GetStandardValues(ITypeDescriptorContext context). I use
    var myClass = context.Instance as MyClass.Options;

    The third approach also uses a class and requires, in the TypeConverter function, an override for StandardValuesCollection GetStandardValues(ITypeDescriptorContext context). I use
    var choices = context.PropertyDescriptor.Attributes.OfType<ListT ypeConverterAttribute>().FirstOrDefault()?.List;

    (Yes, I am aware this is C#6 and wont compile in NT but I am simply showing it here for succintness. That is not the issue.)

    The issue is that the ITypeDescriptorContext context is null. Does NT actually return a property grid context that is not null?

    Any suggestions would be greatly appreciated. Thank you.

    #2
    Hello Zeos6,

    Thank you for the post.

    Just to confirm, you are specifically trying to create a dropdown similar to the Enum dropdown rather than using a Collection editor is that right? The current type converters in the sample demonstrate using a Collection<T> for a list of items that are dynamically created, I am unaware of any existing sample which uses a dropdown for anything other than an Enum which is not dynamically created.

    In your first test, I would not be certain why the blank line would exist, it is possible this is just a result of the syntax used and there is something still needed to fix that. This may be something you can do more research by using general WPF searches online surrounding the elements you used in that test. Creating type converters/GUI design is not something we have a great deal of information or samples for however there is a large amount of information in external resources on these subjects. If you have a sample which isolates this test by its self that you can upload, we could review that further together.

    The second test I don't see a question or outcome here, I take it this also has the context as null as described in the third test? Can you clarify this test?

    The issue is that the ITypeDescriptorContext context is null. Does NT actually return a property grid context that is not null?
    Without knowing where this is used I couldn't really say, the sample type converter has ITypeDescriptorContext in a few areas and they are frequently null, however, they are not null at some times. You may try a print in the areas where this is used like the following to see if it ever becomes not null how it is currently used:
    Code:
    NinjaTrader.Code.Output.Process("NameOfMethod " +(context == null).ToString(), PrintTo.OutputTab1);

    For the third approach I couldn't really comment on as that is beyond NT8's .net version, I would likely suggest taking a step back to the first test as it sounds like you had that part working.


    I look forward to being of further assistance.
    JesseNinjaTrader Customer Service

    Comment


      #3
      Hi Jesse,

      Thank you for your reply.

      You are correct. I am trying to create a dynamically created dropdown similar to the Enum dropdown rather than using a Collection editor derived from the UITypeEditor. I have no issues with the Enum converter. I am however trying to use a list of strings (or array of strings) rather than enums for the dropdown. This should be doable.

      As far as the first blank line in the dropdown, this seems to be due a combobox selected item index/property issue or a line break. Yes, there is a lot of information on WPF comboboxes but unfortunately most of it relies on Xaml so it is not of much use as I can't see how to get this information in the TypeConverter. Also, I have checked the code again and the issue persists.

      The second approach uses a class to create the list in the constructor. The list is read via the class property 'Options". I need to get an instance of the Class creating the properties and that requires the context.

      public override StandardValuesCollection GetStandardValues(ITypeDescriptorContext context)
      {
      var myClass = context.Instance as MyClass.Options;
      if (myClass != null)
      return new StandardValuesCollection(myClass.Options);

      return base.GetStandardValues(context);
      }

      That above code should work. Hence the context question.

      I actually tried your suggestion and it appears that the context is not null. I will look at creating a ITypeDescriptorContext.Instance. Perhaps that's where the issue lies.

      Thanks for your help Jesse. It is appreciated.

      Comment

      Latest Posts

      Collapse

      Topics Statistics Last Post
      Started by usazencort, Today, 01:16 AM
      0 responses
      1 view
      0 likes
      Last Post usazencort  
      Started by kaywai, 09-01-2023, 08:44 PM
      5 responses
      603 views
      0 likes
      Last Post NinjaTrader_Jason  
      Started by xiinteractive, 04-09-2024, 08:08 AM
      6 responses
      22 views
      0 likes
      Last Post xiinteractive  
      Started by Pattontje, Yesterday, 02:10 PM
      2 responses
      20 views
      0 likes
      Last Post Pattontje  
      Started by flybuzz, 04-21-2024, 04:07 PM
      17 responses
      230 views
      0 likes
      Last Post TradingLoss  
      Working...
      X