• If this is your first visit, you will have to register before you can post. To view messages, please scroll below and select the forum that you would like to visits. Questions? Be sure to check out the Forum FAQ.

Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

NTGrid

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

    NTGrid

    Hi there,

    I am creating an AddOn that will use a DataGrid. I find that when I put a DataGrid on an NTWindow, it does not inherit the styles like buttons and comboboxes do. I can see the grids used in NinjaTrader are NTGrid objects. Can you give an example of how we can use the NTGrid object in an AddOn binding to an List of objects.

    Regards,

    codeOwl.

    #2
    Hello,

    Thank you for the question.

    I am currently working with product management on this to see what the suggested approach would be.

    I am checking both if the NTGrid would be suggested and if not if there are suggestions on the correct resources to use with DataGrid specifically.

    Once I have further information on this I will reply back.

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

    Comment


      #3
      If you wanna use NTGrid, then you need to use DataSource property, to assign a list to it.
      I typically use an ObservableCollection<T> for this but you're welcome to use any collection.

      It took a lot guessing but then I saw that NTGrid was inheriting from XamDataGrid (Infragistics control) and I was able to get to look like the Market Analyzer using this -
      Code:
      public class TestTabPage : NTTabPage
      {
              private NTGrid grid;
      
              ObservableCollection<MyAlert> testCollection;
      
      	public XABCDPatternTabPage()
      	{
      		BuildDataGrid();
      
      		testCollection = new ObservableCollection<MyAlert>();
      		for (int i = 0; i < 10; i++)
      		{
      			MyAlert = new MyAlert
      			{
      				Price = 15,
      				HighPrice = 16,
      				LowPrice = 14,
      				IsBull = true,
      				Symbol = "EURUSD",
      				Targets = new[] { 16.5, 17, 17.5 },
      				Time = DateTime.Now.ToShortDateString()
      			};
      			testCollection.Add(td);
      		}
      		grid.DataSource = testCollection;
      
      		AddChild(grid);
              }
              private void BuildDataGrid()
              {
      	        grid = new NTGrid();
      	        grid.GroupByAreaLocation = GroupByAreaLocation.None;
      	        grid.FieldLayouts.Add(new FieldLayout());
      	        grid.FieldSettings = new FieldSettings()
      	        {
      		        AllowEdit = false,
      		        CellClickAction = CellClickAction.SelectRecord,
      		        LabelTextAlignment = TextAlignment.Center,
      		        LabelTextWrapping = TextWrapping.NoWrap
      	        };
      	        grid.FieldLayoutSettings = new FieldLayoutSettings()
      	        {
      		        AutoFitMode = AutoFitMode.Always,
      		        AllowDelete = false,
      		        AllowFieldMoving = AllowFieldMoving.WithinLogicalRow,
      		        AutoGenerateFields = true,
      		        FixedRecordSortOrder = FixedRecordSortOrder.FixOrder,
      		        MaxSelectedRecords = 1,
      		        SelectionTypeRecord = SelectionType.Single,
      		        HeaderPrefixAreaDisplayMode = HeaderPrefixAreaDisplayMode.None,
      		        RecordSelectorLocation = RecordSelectorLocation.None,
      		        RecordSeparatorLocation = RecordSeparatorLocation.None
      	        };
              }
      }
      Last edited by Calonious; 03-07-2016, 03:08 PM.

      Comment


        #4
        Jessie,

        Thanks for the update mate. I look forward to the response.

        Regards,

        codeOwl

        Comment


          #5
          Hello,

          Thank you for the reply.

          I have put the question in for this to Product Management to see if we could get a sample of this concept. While waiting to hear back Calonious has provided an excellent complete and functioning sample of building a NT grid. This could be used in an Addon as asked.


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

          Comment


            #6
            Calonious,

            Thanks for the code sample mate. Much appreciated. I too saw that NTGrid inherited from the Infragistics XamDataGrid, which made me wonder if it was the best choice for a simple grid. I tried to use the XamDataGrid directly as a proof of concept after I go the following error when attempting to create an NTGrid:

            An unhandled exception of type 'System.Windows.Markup.XamlParseException' occurred in PresentationFramework.dll

            Attempting to use the XamlDataGrid directly resulted in a licensing error.

            So then I came here to ask what the correct way to use it is.

            Your code gives me the following error:
            An exception of type 'System.TypeInitializationException' occurred in TestWPF.exe but was not handled in user code

            Additional information: The type initializer for '<Module>' threw an exception.

            I have created a stand alone WPF test app... that uses NT and Infragistics dlls and NT BluePrint Skin as a development testbed... as it is so much faster to start, stop, make a change and start again than NT is... also the location of my Add-In is on a chart window, so I have to jump through a few hoops just to get the thing open... and then if it throws an exception during testing, NT crashes... and the whole process takes ages... so designing the UI in a one page WPF app that you can just press Play to debug on has saved heaps of time...

            The error above with the NTGrid I get just by creating an instance of it in the code behind. There is no XMAL other than the window element and a layout grid element, and I haven't even added the instance to the page. I get the same error with a full test that assigns a data-source and adds the grid to the page.

            Regards,

            codeOwl
            Last edited by codeowl; 03-11-2016, 06:33 PM. Reason: fixed typos

            Comment


              #7
              You by chance have a quick sample that reproduces it? or give me more detail in how you are calling and building it? I've been using this since beta 3 and haven't had any issues with it.

              Comment


                #8
                Calonious,

                Thanks for the followup mate. I have attached a test project that demonstrates the error:

                An exception of type 'System.TypeInitializationException' occurred in TestWPF.exe but was not handled in user code

                Additional information: The type initializer for '<Module>' threw an exception.

                Using the sample code you posted.

                I had to remove the bin folder to get it small enough to be under the 1 mb attachment limit, but I have attached an image that shows the project references.

                Thanks for your input.

                Regards,

                codeOwl
                Attached Files

                Comment


                  #9
                  You're not going to be able to open up an NTGrid outside of NT, due to licensing with Infragistics.

                  Best bet is to build a Add-on window and test page that throws it on.

                  I put one together based off our sample and attached it.
                  Attached Files

                  Comment


                    #10
                    Unfortunately, I get an import error that the methods used already exist.

                    Comment


                      #11
                      Calonious,

                      Thanks for the time you have put into this mate. Much appreciated.

                      I attempted to import the Add-On and got the same error:

                      Time Category Message
                      11/03/2016 8:02:57 PM Default Error compiling import assembly: [PATHREMOVED]bin\Custom\AddOns\SampleNTGrid.cs(10,28) : error CS0234: The type or namespace name 'Controls' does not exist in the namespace 'Infragistics.Windows' (are you missing an assembly reference?)

                      But I then created an add-on manually and pasted the guts of your code in, and after adding some references got it to work.

                      I am not sure if this solution will work for me though as I have created our AddOn in a separate DLL to NT, which means it resides in a separate VS project. Plus the WPF DataGrid would be more that adequate for what we need and less complex to implement.

                      I will ask NT Support if they can give us some skinning options for the standard WPF DataGrid.

                      Thanks again for your time mate.

                      Regards,

                      codeOwl
                      Last edited by codeowl; 03-11-2016, 04:57 AM.

                      Comment


                        #12
                        Jessie,

                        How did you go with your inquiry?

                        As we our AddOn is built in a separate project to NT, I don't think the NT grid will work, plus we really only need a simple grid, so the WPF DataGrid would be more than adequate. Can you provide use with some styles for that DataGrid that make it look the same as the NT grid in colors as it looks like we will run into licensing issues with the NTGrid as it inherits from the Infrigistics XamDataGrid?

                        Regards,

                        codeOwl
                        Last edited by codeowl; 03-11-2016, 06:34 PM. Reason: fixed typeo

                        Comment


                          #13
                          Calonious,

                          I have been playing around with the sample code you posted and I have been able to get the NTGrid to do mostly what I want. The one thing I haven't been able to work out is get the Field Label and Cell Content to center. I have tried a number of approaches I found on the Infragistics forum, but none of them worked.

                          I have one column that is an ID, one that is a DateTime, and one that is an image. I want to center the image, and the DateTime columns. There is no editor in the DateTime column it is a read-only grid.

                          Some of the infragistics forum posts I have read on the subject:

                          Cell Content Alignment:
                          http://www.infragistics.com/communit...18.aspx#312218
                          http://www.infragistics.com/communit...632.aspx#70632
                          http://www.infragistics.com/communit...126.aspx#87126

                          Field Label Alignment:
                          http://www.infragistics.com/communit...s/t/73362.aspx

                          My current attempt:
                          I have AutoGenerateFields = false and I have defined my columns as follows:

                          Code:
                          #region Create CellValuePresenterStyle 
                          
                          Style _CellValuePresenterStyle = new Style();
                          ControlTemplate _ControlTemplate = new ControlTemplate();
                          Image _Image = new Image();
                          _Image.VerticalAlignment = VerticalAlignment.Center;
                          _Image.HorizontalAlignment = HorizontalAlignment.Center;
                          FrameworkElementFactory _FrameworkElementFactory = new FrameworkElementFactory(typeof(Image));
                          _FrameworkElementFactory.SetBinding(Image.SourceProperty, new Binding("IconColumn"));
                          DataTemplate _DataTemplate = new DataTemplate();
                          _DataTemplate.VisualTree = _FrameworkElementFactory;
                          _CellValuePresenterStyle.Setters.Add(new Setter(TemplateProperty, _DataTemplate));
                          _CellValuePresenterStyle.Setters.Add(new Setter(VerticalAlignmentProperty, VerticalAlignment.Center));
                          _CellValuePresenterStyle.Setters.Add(new Setter(FrameworkElement.HorizontalAlignmentProperty, HorizontalAlignment.Center)); 
                          _CellValuePresenterStyle.Setters.Add(new Setter(Control.HorizontalContentAlignmentProperty, HorizontalAlignment.Center)); 
                          
                          #endregion
                          Code:
                          #region Create Grid Fields
                          
                          grid.FieldLayouts.Add(new FieldLayout());
                          Field _Field = new Field("ID", "ID") { Width = new FieldLength(50, FieldLengthUnitType.Pixel) };
                          _Field.Settings.CellHeight = 20;
                          _Field.Settings.LabelTextAlignment = TextAlignment.Center;
                          grid.FieldLayouts[0].Fields.Add(_Field);
                          _Field = new Field("DateTimeCol", "DateTime Column") { Width = new FieldLength(50, FieldLengthUnitType.Star) };
                          _Field.Settings.CellHeight = 20;
                          grid.FieldLayouts[0].Fields.Add(_Field);
                          _Field = new Field("IconColumn", "Icon Column") { Width = new FieldLength(60, FieldLengthUnitType.Pixel) };
                          _Field.Settings.CellHeight = 20;
                          _Field.Settings.AllowEdit = false;
                          _Field.Settings.CellPresenterStyle = _CellValuePresenterStyle;
                          _Field.Settings.LabelTextAlignment = TextAlignment.Center;
                          grid.FieldLayouts[0].Fields.Add(_Field);
                          
                          #endregion
                          However none of the column headers are centered and the image is also not centered, everything remains left aligned.

                          Have you done any grids with Field Label and Cell Content alignment working?

                          Once again thanks for your time,

                          Regards,

                          codeOwl
                          Last edited by codeowl; 03-13-2016, 08:19 PM.

                          Comment


                            #14
                            Just letting you know I'm still working on this. Just getting the information together and testing. My first thought was the properties that I had shared and if any of them are interfering with it, so double check those in your project.

                            Second, you can use this in a separate Dll in a different VS project as that is what I am doing. What I mean't earlier was that you won't be able to throw it in a new executable project since there is no licensing attached to it. If you load a separate Dll in NT using this NTGrid then it uses the licensing that is embedded with NT, since NT is the calling thread so to speak.

                            Comment


                              #15
                              Calonious,

                              Thanks for the update mate. The other settings I am running are as follows:

                              Code:
                              #region Define Field Settings
                              
                              grid.FieldSettings = new FieldSettings()
                              {
                                  AllowEdit = false,
                                  CellClickAction = CellClickAction.SelectRecord,
                                  LabelTextWrapping = TextWrapping.NoWrap
                              };
                                          
                              grid.FieldLayoutSettings = new FieldLayoutSettings()
                              {
                                  AutoFitMode = AutoFitMode.Never,
                                  AllowDelete = true,
                                  AllowFieldMoving = AllowFieldMoving.No,
                                  AutoGenerateFields = false,
                                  FixedRecordSortOrder = FixedRecordSortOrder.Default,
                                  MaxSelectedRecords = 1,
                                  SelectionTypeRecord = Infragistics.Windows.Controls.SelectionType.Single,
                                  HeaderPrefixAreaDisplayMode = HeaderPrefixAreaDisplayMode.None,
                                  RecordSelectorLocation = RecordSelectorLocation.None,
                                  RecordSeparatorLocation = RecordSeparatorLocation.None,
                                  AllowAddNew = false
                              };
                              
                              #endregion
                              But I can't see any of these causing the problem...

                              Regards,

                              codeOwl

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by dltharpe, Today, 09:17 AM
                              0 responses
                              7 views
                              0 likes
                              Last Post dltharpe  
                              Started by HiddenPhilosopher, Today, 06:45 AM
                              0 responses
                              7 views
                              0 likes
                              Last Post HiddenPhilosopher  
                              Started by PG7940, Today, 04:26 AM
                              0 responses
                              11 views
                              0 likes
                              Last Post PG7940
                              by PG7940
                               
                              Started by marcus2300, Today, 02:25 AM
                              0 responses
                              2 views
                              0 likes
                              Last Post marcus2300  
                              Started by drpapp, 01-24-2019, 06:57 AM
                              5 responses
                              70 views
                              0 likes
                              Last Post pjsmith
                              by pjsmith
                               
                              Working...
                              X