Replies

TraderExperto
31 Jul 2023, 20:05 ( Updated at: 21 Dec 2023, 09:23 )

RE: RE: combobox.SelectedItemChanged

TraderExperto said: 

amusleh said: 

Hi,

This works fine for me on 4.6.2 and .NET 6:

using System;using System.Collections.Generic;using System.Linq;using System.Text;using cAlgo.API;using cAlgo.API.Collections;using cAlgo.API.Indicators;using cAlgo.API.Internals;namespace cAlgo{    [Indicator(AccessRights = AccessRights.None)]    public class ComboBoxTest : Indicator    {        private ComboBox myDropList;        protected override void Initialize()        {            myDropList = new ComboBox            {                   Width = 100,                Height = 20,                HorizontalContentAlignment = HorizontalAlignment.Center,                VerticalContentAlignment = VerticalAlignment.Center            };                        myDropList.AddItem("Item 1");            myDropList.AddItem("Item 2");            myDropList.AddItem("Item 3");                        Chart.AddControl(myDropList);                        myDropList.SelectedItemChanged += myDropList_SelectedIndexChanged;        }                private void myDropList_SelectedIndexChanged(ComboBoxSelectedItemChangedEventArgs e)        {            if (myDropList.SelectedIndex != -1)            {                string selectedValue = myDropList.SelectedItem.ToString();                switch (selectedValue)                {                    case "Item 1":                        Print("Item 1 selected");                        break;                    case "Item 2":                        Print("Item 2 selected");                        break;                    case "Item 3":                        Print("Item 3 selected");                        break;                    default:                        MessageBox.Show("The selected item was not recognized. Please contact the developer for assistance. Telegram: @DelFonseca");                        break;                }            }            else            {                MessageBox.Show("Please select an item from the dropdown list.");            }        }        public override void Calculate(int index)        {            //...        }    }}

 

Check event signature before using it: SelectedItemChanged Event - cTrader Automate API

I'm getting this on Ctrader 3.8.17 the code has only Item 1, Item 2, Item 3 and i'm getting it twice for every item. And when i click on the additional items it returns the message as it doesn't exist! Is anything wrong with this example or is this a bug?

 

Ok it looks like if you put the Combobox as a child of a Border Control the problem is solved. Here is the code!

protected override void Initialize()
        {
            myDropList = new ComboBox
            {
                Width = 100,
                Height = 20,
                HorizontalContentAlignment = HorizontalAlignment.Center,
                VerticalContentAlignment = VerticalAlignment.Center
            };

            myDropList.AddItem("Item 1");
            myDropList.AddItem("Item 2");
            myDropList.AddItem("Item 3");

            myDropList.SelectedIndex = 0;

            Border myDropListBorder = new Border()
            {
                Child = myDropList,
            };
    
            Chart.AddControl(myDropListBorder);

            myDropList.SelectedItemChanged += myDropList_SelectedIndexChanged;

        }

 


@TraderExperto

TraderExperto
31 Jul 2023, 19:46 ( Updated at: 21 Dec 2023, 09:23 )

RE: combobox.SelectedItemChanged

amusleh said: 

Hi,

This works fine for me on 4.6.2 and .NET 6:

using System;using System.Collections.Generic;using System.Linq;using System.Text;using cAlgo.API;using cAlgo.API.Collections;using cAlgo.API.Indicators;using cAlgo.API.Internals;namespace cAlgo{    [Indicator(AccessRights = AccessRights.None)]    public class ComboBoxTest : Indicator    {        private ComboBox myDropList;        protected override void Initialize()        {            myDropList = new ComboBox            {                   Width = 100,                Height = 20,                HorizontalContentAlignment = HorizontalAlignment.Center,                VerticalContentAlignment = VerticalAlignment.Center            };                        myDropList.AddItem("Item 1");            myDropList.AddItem("Item 2");            myDropList.AddItem("Item 3");                        Chart.AddControl(myDropList);                        myDropList.SelectedItemChanged += myDropList_SelectedIndexChanged;        }                private void myDropList_SelectedIndexChanged(ComboBoxSelectedItemChangedEventArgs e)        {            if (myDropList.SelectedIndex != -1)            {                string selectedValue = myDropList.SelectedItem.ToString();                switch (selectedValue)                {                    case "Item 1":                        Print("Item 1 selected");                        break;                    case "Item 2":                        Print("Item 2 selected");                        break;                    case "Item 3":                        Print("Item 3 selected");                        break;                    default:                        MessageBox.Show("The selected item was not recognized. Please contact the developer for assistance. Telegram: @DelFonseca");                        break;                }            }            else            {                MessageBox.Show("Please select an item from the dropdown list.");            }        }        public override void Calculate(int index)        {            //...        }    }}

 

Check event signature before using it: SelectedItemChanged Event - cTrader Automate API

I'm getting this on Ctrader 3.8.17 the code has only Item 1, Item 2, Item 3 and i'm getting it twice for every item. And when i click on the additional items it returns the message as it doesn't exist! Is anything wrong with this example or is this a bug?


@TraderExperto

TraderExperto
12 Oct 2022, 02:39 ( Updated at: 21 Dec 2023, 09:22 )

Just a little example on how to use the new Custom Window

        public ToggleButton ShowPanel;
        
        public Window W;

        protected override void Initialize()
        {     
             ShowPanel = new ToggleButton 
            {
                Width = 60,
                Height = 25,
                Text = "Show",
                VerticalAlignment = VerticalAlignment.Top,
                HorizontalAlignment = HorizontalAlignment.Left,
                Margin = "20 110 0 0",
                BackgroundColor = Color.FromHex("FFBF9100"),
                FontWeight = FontWeight.DemiBold
            };
            
            Chart.AddControl(ShowPanel);

            ShowPanel.Checked += ShowPanel_Checked;
            ShowPanel.Unchecked += ShowPanel_Unchecked;
            
            W = new Window();
            
            W.Width = 600;
            W.Height = 400;
            
            W.MinWidth = 500;
            W.MinHeight = 300;
            
            W.MaxWidth = 700;
            W.MaxHeight = 500;
            
            W.ResizeMode = ResizeMode.CanResize;
            
            W.BackgroundColor = "FF013861";
            var wrapPanel = new WrapPanel();

            for (var i = 0; i < 10; i++)
            {
                var button = new Button 
                {
                    Text = "Click Me",
                    BackgroundColor = "#0E9247",
                    Margin = 5
                };
                wrapPanel.AddChild(button);
            }
            W.Child = wrapPanel;
        }

        private void ShowPanel_Unchecked(ToggleButtonEventArgs obj)
        {
            ShowPanel.Text = "Show";
            W.Hide();
        }

        private void ShowPanel_Checked(ToggleButtonEventArgs obj)
        {   
            ShowPanel.Text = "Hide";
            
            W.WindowStartupLocation = WindowStartupLocation.CenterScreen;
            W.Show();
        }

 

 

 

 


@TraderExperto

TraderExperto
17 Sep 2020, 04:24

Very Big Ctrader Improvement

I think it would help a lot not just the developers, but all the Ctrader users too. Given the possibility to create Plugins will improve a lot the user experience through more advanced applications that can be installed on the Ctrader platform, like others Platforms.


@TraderExperto