Merge Cells on data grid

Created at 24 Feb 2023, 23:26
How’s your experience with the cTrader Platform?
Your feedback is crucial to cTrader's development. Please take a few seconds to share your opinion and help us improve your trading experience. Thanks!
DelFonseca's avatar

DelFonseca

Joined 25.06.2017

Merge Cells on data grid
24 Feb 2023, 23:26


Hi all,

How can I merge cells? For example, merge the 1st row of two columns.
I have tried several ways but without success.

Thanks in advance

 

using System;
using cAlgo.API;

namespace cAlgo
{
    [Indicator(IsOverlay = true, TimeZone = TimeZones.UTC, AccessRights = AccessRights.None)]
    public class MergeCells : Indicator
    {    
        private Grid dataGrid;

        protected override void Initialize()
        {
            dataGrid = new Grid(5, 2);
            dataGrid.Width = 100;
            dataGrid.Height = 100;
            dataGrid.HorizontalAlignment = HorizontalAlignment.Center;
            dataGrid.VerticalAlignment = VerticalAlignment.Center;
            dataGrid.ShowGridLines = true;
            
            Chart.AddControl(dataGrid);
        }

        public override void Calculate(int index)
        {

        }
    }
}

 


@DelFonseca
Replies

PanagiotisChar
28 Feb 2023, 09:23

Hi Delmar,

My solution is to place grids within grids so that I can achieve the layout I want. I hope this helps.

Aieden Technologies

Need help? Join us on Telegram

Need premium support? Trade with us

 


@PanagiotisChar

DelFonseca
28 Feb 2023, 23:44

RE:

PanagiotisChar said:

(...)


Hello my Friend,

First of all, I hope your career path is being a success....

Thanks for your reply, in the meantime I have resolved and thought the opposite, if I want to do merging, why not start with 1 column and add what I want like "unmerge"? Solved it :)

Thanks!!

Here is an example in case someone in the future needs it.

using System;
using cAlgo.API;

namespace cAlgo
{
    [Indicator(IsOverlay = true, TimeZone = TimeZones.UTC, AccessRights = AccessRights.None)]
    public class MergeCells : Indicator
    {
    
        private Grid mainDataGrid, insideDataGrid;

        protected override void Initialize()
        {
            mainDataGrid = new Grid(5, 1)
            {
                Width = 100,
                Height = 100,
                HorizontalAlignment = HorizontalAlignment.Center,
                VerticalAlignment = VerticalAlignment.Center,
                ShowGridLines = true,            
            };
            
            TextBlock MergeCellsText = new TextBlock()
            {
                Text = "Merged Cells",
                HorizontalAlignment = HorizontalAlignment.Center,
                VerticalAlignment = VerticalAlignment.Center,
            };
            mainDataGrid.AddChild(MergeCellsText, 0, 0);          
            
            insideDataGrid = new Grid(1, 3);
            insideDataGrid.ShowGridLines = true;
            
            for (int i = 0; i < 3; i++)
            {
                TextBlock ExampleText = new TextBlock()
                {
                    Text = i.ToString(),
                    HorizontalAlignment = HorizontalAlignment.Center,
                    VerticalAlignment = VerticalAlignment.Center,
                };
                insideDataGrid.AddChild(ExampleText, 0, i);
            }
            
            mainDataGrid.AddChild(insideDataGrid, 1, 0);
            
            Chart.AddControl(mainDataGrid);            
        }

        public override void Calculate(int index)
        {

        }
    }
}

 


@DelFonseca