This is a migrated thread and some comments may be shown as answers.
Inherited DateTimePicker Focus Border Problem
0 Answers 8 Views
This is a migrated thread and some comments may be shown as answers.
Leandro
Top achievements
Rank 1
Leandro asked on 05 Sep 2018, 04:00 PM

Hey guys, I've inherited RadDateTimePicker to do a better handling of null value with databinding and the problem is when it got focused by Tab key it borders don't change as it should be. Ive tried setting focus to DateTimePickerElement when my picker got focus, but it didn't solve as well. 

 

 public partial class NossoRadDateTimePicker : RadDateTimePicker
    {
        public NossoRadDateTimePicker()
        {
            InitializeComponent();
            TabStop = true;
            this.ValueChanged += NossoRadDateTimePicker_ValueChanged;
            this.GotFocus += NossoRadDateTimePicker_GotFocus;
        }

        private void NossoRadDateTimePicker_GotFocus(object sender, EventArgs e)
        {
            base.DateTimePickerElement.Focus();
        }

        private void NossoRadDateTimePicker_ValueChanged(object sender, EventArgs e)
        {
            if (ShowCheckBox && checking == false)
                this.Checked = true;

        }

        [Browsable(false), EditorBrowsable(EditorBrowsableState.Never), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
        public new DateTime? NullableValue
        {
            get
            {
                throw new Exception("Use Value");
            }
            set
            {
                throw new Exception("Use Value");
            }
        }

        [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
        /// <summary>
        /// Poderá retornar null caso use o checkbox e ele não esteja checkado
        /// </summary>
        public new DateTime? Value
        {
            get
            {
                DateTime? valor = base.Value;

                if (ShowCheckBox && Checked == false)
                    valor = null;

                return valor;
            }
            set
            {
                //garantir que essa bosta n sete valor fora do range de datas
                if (value != null)
                {
                    value = value > MaxDate ? MaxDate : value;
                    value = value < MinDate ? MinDate : value;
                    Checked = true;
                }
                else if (ShowCheckBox)
                    Checked = false;

                checking = true;
                base.Value = value ?? DateTime.Now;
                checking = false;

            }
        }

        protected override void OnKeyDown(KeyEventArgs e)
        {
            if (e.KeyData == Keys.Space)
            {
                this.Checked = !this.Checked;
            }
            else
            {
                base.OnKeyDown(e);

            }
        }

        bool checking;
    }

No answers yet. Maybe you can help?

Asked by
Leandro
Top achievements
Rank 1
Share this question
or