Read Only for all editors

34 posts, 5 answers
  1. DoomerDGR8
    DoomerDGR8 avatar
    133 posts
    Member since:
    Aug 2010

    Posted 31 Jan 2011 Link to this post

    I want to have a readonly functionality implemented in DropDown, DropDownList. Marking them Enabled = False is the most ugly solution. By readonly, I mean to say the equivalent feature of the TextBox. This is most useful for show View-Only Forms. Using a common form for showing information and editing information becomes very elegant if all Editor support readonly. I refer to DateTimePickers and Checkboxes too. Having them set to disable is just not right. Also, having labels and/or readonly-textboxes in the dropdown's place while in readonly/view mode is also more of a head-ache.
  2. Richard Slade
    Richard Slade avatar
    3000 posts
    Member since:
    May 2009

    Posted 31 Jan 2011 Link to this post

    Hello Hassan,

    Hope you're well.
    What you'll need to do is to inherit from the standard RadControls, and add some extra properties to allow a ReadOnly state.

    I have done a small exmaple for you here that will allow you to set the RadDropDownList to IsReadOnly = true / false. This works by stopping the pop up from opening and settig the textboxitem to ReadOnly if the IsReadOnly flag is set to true.

    Form1 Designer
    <Global.Microsoft.VisualBasic.CompilerServices.DesignerGenerated()> _
    Partial Class Form1
        Inherits System.Windows.Forms.Form
      
        'Form overrides dispose to clean up the component list.
        <System.Diagnostics.DebuggerNonUserCode()> _
        Protected Overrides Sub Dispose(ByVal disposing As Boolean)
            Try
                If disposing AndAlso components IsNot Nothing Then
                    components.Dispose()
                End If
            Finally
                MyBase.Dispose(disposing)
            End Try
        End Sub
      
        'Required by the Windows Form Designer
        Private components As System.ComponentModel.IContainer
      
        'NOTE: The following procedure is required by the Windows Form Designer
        'It can be modified using the Windows Form Designer.  
        'Do not modify it using the code editor.
        <System.Diagnostics.DebuggerStepThrough()> _
        Private Sub InitializeComponent()
            Dim RadListDataItem1 As Telerik.WinControls.UI.RadListDataItem = New Telerik.WinControls.UI.RadListDataItem()
            Dim RadListDataItem2 As Telerik.WinControls.UI.RadListDataItem = New Telerik.WinControls.UI.RadListDataItem()
            Dim RadListDataItem3 As Telerik.WinControls.UI.RadListDataItem = New Telerik.WinControls.UI.RadListDataItem()
            Me.MyRadDropDownList1 = New RadControls_ReadOnly.MyRadDropDownList()
            Me.RadCheckBox1 = New Telerik.WinControls.UI.RadCheckBox()
            CType(Me.MyRadDropDownList1, System.ComponentModel.ISupportInitialize).BeginInit()
            CType(Me.RadCheckBox1, System.ComponentModel.ISupportInitialize).BeginInit()
            Me.SuspendLayout()
            '
            'MyRadDropDownList1
            '
            Me.MyRadDropDownList1.IsReadOnly = False
            RadListDataItem1.Selected = True
            RadListDataItem1.Text = "ListItem 1"
            RadListDataItem1.TextWrap = True
            RadListDataItem2.Text = "ListItem 2"
            RadListDataItem2.TextWrap = True
            RadListDataItem3.Text = "ListItem 3"
            RadListDataItem3.TextWrap = True
            Me.MyRadDropDownList1.Items.Add(RadListDataItem1)
            Me.MyRadDropDownList1.Items.Add(RadListDataItem2)
            Me.MyRadDropDownList1.Items.Add(RadListDataItem3)
            Me.MyRadDropDownList1.Location = New System.Drawing.Point(32, 142)
            Me.MyRadDropDownList1.Name = "MyRadDropDownList1"
            Me.MyRadDropDownList1.ShowImageInEditorArea = True
            Me.MyRadDropDownList1.Size = New System.Drawing.Size(207, 19)
            Me.MyRadDropDownList1.TabIndex = 1
            Me.MyRadDropDownList1.Text = "ListItem 1"
            '
            'RadCheckBox1
            '
            Me.RadCheckBox1.Location = New System.Drawing.Point(32, 91)
            Me.RadCheckBox1.Name = "RadCheckBox1"
            Me.RadCheckBox1.Size = New System.Drawing.Size(159, 18)
            Me.RadCheckBox1.TabIndex = 2
            Me.RadCheckBox1.Text = "Is RadDropDown Read Only"
            '
            'Form1
            '
            Me.AutoScaleDimensions = New System.Drawing.SizeF(6.0!, 13.0!)
            Me.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font
            Me.ClientSize = New System.Drawing.Size(284, 262)
            Me.Controls.Add(Me.RadCheckBox1)
            Me.Controls.Add(Me.MyRadDropDownList1)
            Me.Name = "Form1"
            Me.Text = "Form1"
            CType(Me.MyRadDropDownList1, System.ComponentModel.ISupportInitialize).EndInit()
            CType(Me.RadCheckBox1, System.ComponentModel.ISupportInitialize).EndInit()
            Me.ResumeLayout(False)
            Me.PerformLayout()
      
        End Sub
        Friend WithEvents MyRadDropDownList1 As RadControls_ReadOnly.MyRadDropDownList
        Friend WithEvents RadCheckBox1 As Telerik.WinControls.UI.RadCheckBox
      
    End Class

    Form1.vb
    Public Class Form1
      
        Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
            Me.RadCheckBox1.Checked = Me.MyRadDropDownList1.IsReadOnly
        End Sub
      
        Private Sub RadCheckBox1_ToggleStateChanged(ByVal sender As System.Object, ByVal args As Telerik.WinControls.UI.StateChangedEventArgs) Handles RadCheckBox1.ToggleStateChanged
            If Me.RadCheckBox1.ToggleState = Telerik.WinControls.Enumerations.ToggleState.On Then
                Me.MyRadDropDownList1.IsReadOnly = True
            Else
                Me.MyRadDropDownList1.IsReadOnly = False
            End If
        End Sub
    End Class

    MyRadDropDownList.vb
    Imports System.ComponentModel
      
    Public Class MyRadDropDownList
        Inherits Telerik.WinControls.UI.RadDropDownList
      
        Private m_IsReadOnly As Boolean
        Private Event ReadOnlyChanged As EventHandler(Of EventArgs)
      
        Public Property IsReadOnly As Boolean
            Get
                Return m_IsReadOnly
            End Get
            Set(ByVal value As Boolean)
                m_IsReadOnly = value
                RaiseEvent ReadOnlyChanged(Me, New EventArgs())
            End Set
        End Property
      
        Private Sub Me_ReadOnlyChanged(ByVal sender As Object, ByVal e As EventArgs) Handles Me.ReadOnlyChanged
            If Me.m_IsReadOnly Then
                AddHandler Me.PopupOpening, AddressOf Me_PopUpShowing
                Me.DropDownListElement.TextBox.TextBoxItem.ReadOnly = True
            Else
                RemoveHandler Me.PopupOpening, AddressOf Me_PopUpShowing
                Me.DropDownListElement.TextBox.TextBoxItem.ReadOnly = False
            End If
        End Sub
      
        Private Sub Me_PopUpShowing(ByVal sender As Object, ByVal e As CancelEventArgs)
            e.Cancel = Me.m_IsReadOnly
        End Sub
      
    End Class

    Hope that helps, but let me know if you have any questions
    Richard
  3. UI for WinForms is Visual Studio 2017 Ready
  4. DoomerDGR8
    DoomerDGR8 avatar
    133 posts
    Member since:
    Aug 2010

    Posted 31 Jan 2011 Link to this post

    Ok! Finally something mighty close to what I really needed. And gentlemen, this works nicely for anyone.

    Here is a C# conversation:

    using System;
    using System.ComponentModel;
    using Telerik.WinControls.UI;
     
      public class RadDropDownListCustom : RadDropDownList {
     
        private bool m_IsReadOnly;
        private event EventHandler<EventArgs> ReadOnlyChanged;
     
        public bool IsReadOnly {
          get { return m_IsReadOnly; }
          set {
            m_IsReadOnly = value;
            if (ReadOnlyChanged != null) {
              ReadOnlyChanged(this, new EventArgs());
            }
          }
        }
     
        private void Me_ReadOnlyChanged(object sender, EventArgs e) {
          if (m_IsReadOnly) {
            PopupOpening += Me_PopUpShowing;
            DropDownListElement.TextBox.TextBoxItem.ReadOnly = true;
            DropDownListElement.ArrowButton.Visibility = Telerik.WinControls.ElementVisibility.Collapsed;
     
          } else {
            PopupOpening -= Me_PopUpShowing;
            DropDownListElement.TextBox.TextBoxItem.ReadOnly = false;
            DropDownListElement.ArrowButton.Visibility = Telerik.WinControls.ElementVisibility.Visible;
     
          }
        }
     
        private void Me_PopUpShowing(object sender, CancelEventArgs e) {
          e.Cancel = m_IsReadOnly;
        }
        public RadDropDownListCustom() {
          ReadOnlyChanged += Me_ReadOnlyChanged;
        }
     
      }

    The text-box portion is set read-only and the drop-down is prevented so essentially, the drop-Down becomes read-only. The drop-down arrow is also hidden as well.

    Note, I have this for a DateTimePicker

    using System;
    using System.ComponentModel;
    using Telerik.WinControls.UI;
     
      public class RadDateTimePickerCustom : RadDateTimePicker {
     
        private bool m_IsReadOnly;
        private event EventHandler<EventArgs> ReadOnlyChanged;
     
        public bool IsReadOnly {
          get { return m_IsReadOnly; }
          set {
            m_IsReadOnly = value;
            if (ReadOnlyChanged != null) {
              ReadOnlyChanged(this, new EventArgs());
            }
          }
        }
     
        private void Me_ReadOnlyChanged(object sender, EventArgs e) {
          if (m_IsReadOnly) {
            Opening += Me_Opening;  
         DateTimePickerElement.TextBoxElement.TextBoxItem.ReadOnly = true;
     
          } else {
            Opening -= Me_Opening;
            DateTimePickerElement.TextBoxElement.TextBoxItem.ReadOnly = false;
          }
        }
     
        private void Me_Opening(object sender, CancelEventArgs e) {
          e.Cancel = m_IsReadOnly;
        }
     
        public RadDateTimePickerCustom() {
          ReadOnlyChanged += Me_ReadOnlyChanged;
        }
     
      }

    Don't know yet if the above will work or not. cant test it now. used the online documentation to find the Opening event and the nested TextBox Element. Dont know how to handle if a arrow is shown or an Up-Down? Don't know if the calendar dropdown is controlled. cant get to nested controls. There is a DockLayoutPanel in-between. See image attached.

    Now, is there a similar elegant solution for Check-Box and a Radio-Button as well?
  5. Answer
    Richard Slade
    Richard Slade avatar
    3000 posts
    Member since:
    May 2009

    Posted 31 Jan 2011 Link to this post

    Hello Hassan,

    Here is the one for RadRadioButton

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using Telerik.WinControls.UI;
    using System.ComponentModel;
      
    namespace RadControls_ReadOnly_C
    {
        class MyRadRadioButton : RadRadioButton
        {
            private bool m_IsReadOnly;
            private event EventHandler<EventArgs> ReadOnlyChanged;
      
            public MyRadRadioButton()
            {
                ReadOnlyChanged += Me_ReadOnlyChanged;
            }
      
            public override string ThemeClassName
            {
                get
                {
                    return "Telerik.WinControls.UI.RadRadioButton";
                }
                set
                {
                    base.ThemeClassName = value;
                }
            }
      
            public bool IsReadOnly
            {
                get { return m_IsReadOnly; }
                set
                {
                    m_IsReadOnly = value;
                    if (ReadOnlyChanged != null)
                    {
                        ReadOnlyChanged(this, new EventArgs());
                    }
                }
            }
      
            private void Me_ReadOnlyChanged(object sender, EventArgs e)
            {
                if (m_IsReadOnly)
                {
                    ToggleStateChanging += Me_ToggleStateChanging;
                }
                else
                {
                    ToggleStateChanging -= Me_ToggleStateChanging;
                }
            }
      
            private void Me_ToggleStateChanging(Object sender, StateChangingEventArgs e)
            {
                e.Canceled = this.m_IsReadOnly;
            }
        }
    }


    and if you want to hide the arrow on the RadDropDownList, replace the Me_ReadOnlyChanged event handler in the MyRadDropDownList class with the following one

    private void Me_ReadOnlyChanged(object sender, EventArgs e) {
      if (m_IsReadOnly) {
        PopupOpening += Me_PopUpShowing;
        DropDownListElement.TextBox.TextBoxItem.ReadOnly = true;
        DropDownListElement.ArrowButton.Visibility = Telerik.WinControls.ElementVisibility.Collapsed;
      } else {
        PopupOpening -= Me_PopUpShowing;
        DropDownListElement.TextBox.TextBoxItem.ReadOnly = false;
        DropDownListElement.ArrowButton.Visibility = Telerik.WinControls.ElementVisibility.Visible;
      }
    }

    Hope that helps
    Richard
  6. DoomerDGR8
    DoomerDGR8 avatar
    133 posts
    Member since:
    Aug 2010

    Posted 31 Jan 2011 Link to this post

    All right!

    Already have the arrow-hiding code in my previous post. Also, this bit is necessary?

    public override string ThemeClassName {
      get {
        return "Telerik.WinControls.UI.RadRadioButton";
      }
      set {
        base.ThemeClassName = value;
      }
    }

    Also, my real question is regarding the DateTimePicker. I managed to disable it's drop and editing. Need to hide the arrow button or up/down button whichever is visible. And ... finally, here are the RadRadio and RadCheckBox with ReadOnly support:

    using System;
    using Telerik.WinControls.UI;
     
    namespace ExciteEngine2.MainApplication.BaseUI.Controls {
     
      class RadioButtonCustom : RadRadioButton {
     
        private bool m_IsReadOnly;
        private event EventHandler<EventArgs> ReadOnlyChanged;
     
        public RadioButtonCustom() {
          ReadOnlyChanged += this_ReadOnlyChanged;
          Tag = "edit";
        }
     
        public bool ReadOnly {
          get { return m_IsReadOnly; }
          set {
            m_IsReadOnly = value;
            if (ReadOnlyChanged != null) {
              ReadOnlyChanged(this, new EventArgs());
            }
          }
        }
     
        private void this_ReadOnlyChanged(object sender, EventArgs e) {
          if (m_IsReadOnly) {
            ToggleStateChanging += this_ToggleStateChanging;
          } else {
            ToggleStateChanging -= this_ToggleStateChanging;
          }
        }
     
        private void this_ToggleStateChanging(Object sender, StateChangingEventArgs e) {
          e.Canceled = m_IsReadOnly;
        }
     
      }
     
    }

    using System;
    using Telerik.WinControls.UI;
     
    namespace ExciteEngine2.MainApplication.BaseUI.Controls {
     
      class RadCheckBoxCustom : RadCheckBox {
     
          private bool m_IsReadOnly;
        private event EventHandler<EventArgs> ReadOnlyChanged;
     
        public RadCheckBoxCustom() {
          ReadOnlyChanged += this_ReadOnlyChanged;
          Tag = "edit";
        }
     
        public bool ReadOnly {
          get { return m_IsReadOnly; }
          set {
            m_IsReadOnly = value;
            if (ReadOnlyChanged != null) {
              ReadOnlyChanged(this, new EventArgs());
            }
          }
        }
     
        private void this_ReadOnlyChanged(object sender, EventArgs e) {
          if (m_IsReadOnly) {
            ToggleStateChanging += this_ToggleStateChanging;
          } else {
            ToggleStateChanging -= this_ToggleStateChanging;
          }
        }
     
        private void this_ToggleStateChanging(Object sender, StateChangingEventArgs e) {
          e.Canceled = m_IsReadOnly;
        }
     
      }
     
    }
  7. Answer
    Richard Slade
    Richard Slade avatar
    3000 posts
    Member since:
    May 2009

    Posted 31 Jan 2011 Link to this post

    Hello,

    The ThemeClassName is required. Remove it and you will see that the control doesn't theme.
    To remove the arrow from a RadDropDownList you can use the follwing

    this.radDateTimePicker1.DateTimePickerElement.Children[1].Children[1].Visibility = Telerik.WinControls.ElementVisibility.Collapsed;

    The UpDown Arrows can be controlled with
    this.radDateTimePicker1.ShowUpDown = false;


    hope that helps
    Richard
  8. DoomerDGR8
    DoomerDGR8 avatar
    133 posts
    Member since:
    Aug 2010

    Posted 31 Jan 2011 Link to this post

    Okay, this is important:

    RadioButton
    public override string ThemeClassName {
      get {
        return "Telerik.WinControls.UI.RadRadioButton";
      }
      set {
        base.ThemeClassName = value;
      }
    }

    CheckBox
    public override string ThemeClassName {
      get {
        return "Telerik.WinControls.UI.RadCheckBox";
      }
      set {
        base.ThemeClassName = value;
      }
    }
  9. Answer
    Richard Slade
    Richard Slade avatar
    3000 posts
    Member since:
    May 2009

    Posted 31 Jan 2011 Link to this post

    Corerect, but this is a better way of specifying it

    public class RadCustomButton : RadButton   
        {   
            public override string ThemeClassName   
            {   
                get  
                {   
                    return typeof(RadButton).FullName;   
                }   
            }   
        }  

    Regards,
    Richard

    EDIT// Of course, changing RadButton for whatever control you are inheriting from
  10. DoomerDGR8
    DoomerDGR8 avatar
    133 posts
    Member since:
    Aug 2010

    Posted 31 Jan 2011 Link to this post

    Thing is, we can have either the Up/Down or the arrow for a DateTimePicker... I'm unable to manage that. Remember, under normal circumstances, if we set the UpDown to true on a RadDateTimePicker, the Arrow is replaced.
  11. DoomerDGR8
    DoomerDGR8 avatar
    133 posts
    Member since:
    Aug 2010

    Posted 31 Jan 2011 Link to this post

    BTW, I love this thread.
  12. Richard Slade
    Richard Slade avatar
    3000 posts
    Member since:
    May 2009

    Posted 31 Jan 2011 Link to this post

    Hello,

    this is hte quickest thing I can think of at the moment for the RadDateTimePicker. It takes away the use of the designer, but it quickly gets over the issue with the arrow or drop down. (there may be an easier way, but it does work)

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using Telerik.WinControls.UI;
      
    namespace RadControls_ReadOnly_C
    {
        class MyRadDateTimePicker : RadDateTimePicker
        {
      
      
            public MyRadDateTimePicker() 
            
            
      
      
            public override string ThemeClassName
            {
                get
                {
                    return typeof(RadDateTimePicker).FullName;
                }
            }
      
            public void SetReadOnly(Boolean IsReadOnly, Boolean ShowArrow = false)
            {
                if (IsReadOnly)
                {
                    DateTimePickerElement.Children[1].Children[1].Visibility = Telerik.WinControls.ElementVisibility.Collapsed;
                    base.ShowUpDown = false;
                }
                else
                {
                    if (ShowArrow)
                    {
                        base.ShowUpDown = true;
                    }
                    else
                    {
                        base.ShowUpDown = false;
                        DateTimePickerElement.Children[1].Children[1].Visibility = Telerik.WinControls.ElementVisibility.Visible;
                    }
                }
            }
      
            public new bool ShowUpDown
            {
                get { return base.ShowUpDown; }
            }
      
      
        }
    }

    usage
    this.myRadDateTimePicker1.SetReadOnly(false, true); // not read only - show arrow
    this.myRadDateTimePicker1.SetReadOnly(true); // read only
    this.myRadDateTimePicker1.SetReadOnly(false, false); // not read only - show drop down arrow

    hope that helps
    Richard

    EDIT// Apologies - first pasted code for RadDropDown - corrected to RadDarteTimePicker
  13. DoomerDGR8
    DoomerDGR8 avatar
    133 posts
    Member since:
    Aug 2010

    Posted 31 Jan 2011 Link to this post

    I wonder if DateTimePickerElement.Children[1].Children[1] is *always* the Arrow Button in a DateTimePicker. If DateTimePickerElement.Children[1].Children[2] (for example) is the UpDown button, maybe we can do an if-else on ShowUpDown... again, away from desktop...long live Mobile with Wifi!
  14. Richard Slade
    Richard Slade avatar
    3000 posts
    Member since:
    May 2009

    Posted 31 Jan 2011 Link to this post

    Hi. Give it a go when you can test it and let me know how you get on. We can always tweak it when you've tried it.
  15. Stefan
    Admin
    Stefan avatar
    2890 posts

    Posted 03 Feb 2011 Link to this post

    Hi guys, 

    I noticed that you already have solved most of the discussed questions. In regards to the last question about the children, usually the element three is not changed unless something really requires it. 

    Let me know if I can be of some help, I will be glad to assist you.
     
    All the best,
    Stefan
    the Telerik team
    Q3’10 SP1 of RadControls for WinForms is available for download; also available is the Q1'11 Roadmap for Telerik Windows Forms controls.
  16. DoomerDGR8
    DoomerDGR8 avatar
    133 posts
    Member since:
    Aug 2010

    Posted 03 Feb 2011 Link to this post

    Please elaborate.
  17. DoomerDGR8
    DoomerDGR8 avatar
    133 posts
    Member since:
    Aug 2010

    Posted 07 Feb 2011 Link to this post

    Now that our QA guy is messing arounf with my beautiful application, her reported that typing something into these ReadOnly editors (DropDownList and DateTimePicker) sometimes create abnormal selection of weird values. I tested and found that to be true. It seems too many keystrokes confuse the editor. Any quick remedy?
  18. Richard Slade
    Richard Slade avatar
    3000 posts
    Member since:
    May 2009

    Posted 07 Feb 2011 Link to this post

    Hello Hassan,

    Please could you let us know which editor has this issue and include a sample that demonstrates the problem, if possible with clear steps of how to replicate it and I'll be happy to take a look.
    Rgards,
    Richard
  19. DoomerDGR8
    DoomerDGR8 avatar
    133 posts
    Member since:
    Aug 2010

    Posted 07 Feb 2011 Link to this post

    Here are two editors from the posts above:

    using System;
    using System.ComponentModel;
    using Telerik.WinControls.UI;
     
    namespace ExciteEngine2.MainApplication.BaseUI.Controls {
     
      public class RadDateTimePickerCustom : RadDateTimePicker {
     
        private bool m_IsReadOnly;
        private event EventHandler<EventArgs> ReadOnlyChanged;
     
        public bool ReadOnly {
          get { return m_IsReadOnly; }
          set {
            m_IsReadOnly = value;
            if (ReadOnlyChanged != null) {
              ReadOnlyChanged(this, new EventArgs());
            }
          }
        }
     
        private void this_ReadOnlyChanged(object sender, EventArgs e) {
          if (m_IsReadOnly) {
            Opening += this_Opening;
            DateTimePickerElement.TextBoxElement.TextBoxItem.ReadOnly = true;
            DateTimePickerElement.Children[1].Children[1].Visibility = Telerik.WinControls.ElementVisibility.Collapsed;     
     
          } else {
            Opening -= this_Opening;
            DateTimePickerElement.TextBoxElement.TextBoxItem.ReadOnly = false;
            DateTimePickerElement.Children[1].Children[1].Visibility = Telerik.WinControls.ElementVisibility.Visible;
          }
        }
     
        private void this_Opening(object sender, CancelEventArgs e) {
          e.Cancel = m_IsReadOnly;
        }
     
        public RadDateTimePickerCustom() {
          ReadOnlyChanged += this_ReadOnlyChanged;
          ReadOnly = false;
          Tag = "edit";
        }
     
        public override string ThemeClassName {
          get {
            return typeof(RadDateTimePicker).FullName;
          }
        }   
     
      }
     
    }

    And

    using System;
    using System.ComponentModel;
    using Telerik.WinControls.UI;
     
    namespace ExciteEngine2.MainApplication.BaseUI.Controls {
     
      public class RadDropDownListCustom : RadDropDownList {
     
        private bool m_IsReadOnly;
        private event EventHandler<EventArgs> ReadOnlyChanged;
     
        public bool ReadOnly {
          get { return m_IsReadOnly; }
          set {
            m_IsReadOnly = value;
            if (ReadOnlyChanged != null) {
              ReadOnlyChanged(this, new EventArgs());
            }
          }
        }
     
        private void this_ReadOnlyChanged(object sender, EventArgs e) {
          if (m_IsReadOnly) {
            PopupOpening += this_PopUpShowing;
            DropDownListElement.TextBox.TextBoxItem.ReadOnly = true;
            DropDownListElement.ArrowButton.Visibility = Telerik.WinControls.ElementVisibility.Collapsed;
     
          } else {
            PopupOpening -= this_PopUpShowing;
            DropDownListElement.TextBox.TextBoxItem.ReadOnly = false;
            DropDownListElement.ArrowButton.Visibility = Telerik.WinControls.ElementVisibility.Visible;
     
          }
        }
     
        private void this_PopUpShowing(object sender, CancelEventArgs e) {
          e.Cancel = m_IsReadOnly;
        }
        public RadDropDownListCustom() {
          ReadOnlyChanged += this_ReadOnlyChanged;
          DropDownStyle = Telerik.WinControls.RadDropDownStyle.DropDown;
          AutoCompleteMode = System.Windows.Forms.AutoCompleteMode.SuggestAppend;
          Tag = "edit";
          ReadOnly = false;
        }
     
        public override string ThemeClassName {
          get {
            return typeof(RadDropDownList).FullName;
          }
        }   
     
      }
     
    }

    So, the summary is: Needed to have true Read-Only editors... like a read-only text-box. When set to Read-Only, these above editors behave correctly except that typing too fast sometimes somehow allows the user to change the value.

    I need to to know a method to prevent this from happening.
  20. Richard Slade
    Richard Slade avatar
    3000 posts
    Member since:
    May 2009

    Posted 07 Feb 2011 Link to this post

    Hi Hassan,

    For the RadDropDownList, I have been unable to replicate your issue. I have set a custom RadDropDownList to read only, and no matter how fast I type, it doesn't change.
    For the custom RadDateTimePicker, you are not using the most up to date one I gave you. Please see (from this thread) this answer which is the final one I gave you for the RadDateTimePicker.
    Hope that helps
    Richard
  21. Answer
    Richard Slade
    Richard Slade avatar
    3000 posts
    Member since:
    May 2009

    Posted 07 Feb 2011 Link to this post

    Hassan,

    Here is a slightly updated version of the RadDateTimePicker.

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using Telerik.WinControls.UI;
      
    namespace RadControls_ReadOnly_C
    {
        class MyRadDateTimePicker : RadDateTimePicker
        {
      
      
            public MyRadDateTimePicker() 
            
            
      
      
            public override string ThemeClassName
            {
                get
                {
                    return typeof(RadDateTimePicker).FullName;
                }
            }
      
            public void SetReadOnly(Boolean IsReadOnly, Boolean ShowArrow = false)
            {
                if (IsReadOnly)
                {
                    DateTimePickerElement.Children[1].Children[1].Visibility = Telerik.WinControls.ElementVisibility.Collapsed;
                    DateTimePickerElement.TextBoxElement.TextBoxItem.ReadOnly = true;
                    base.ShowUpDown = false;
                }
                else
                {
                    DateTimePickerElement.TextBoxElement.TextBoxItem.ReadOnly = false;
                    if (ShowArrow)
                    {
                        base.ShowUpDown = true;
                    }
                    else
                    {
                        base.ShowUpDown = false;
                        DateTimePickerElement.Children[1].Children[1].Visibility = Telerik.WinControls.ElementVisibility.Visible;
                    }
                }
            }
      
            public new bool ShowUpDown
            {
                get { return base.ShowUpDown; }
            }
      
      
        }
    }

    regards,
    Richard
  22. DoomerDGR8
    DoomerDGR8 avatar
    133 posts
    Member since:
    Aug 2010

    Posted 07 Feb 2011 Link to this post

    Ok. This DateTime code you gave above, where is the event?

    private event EventHandler<EventArgs> ReadOnlyChanged;

    Or there is no need of it anymore?
  23. Answer
    Richard Slade
    Richard Slade avatar
    3000 posts
    Member since:
    May 2009

    Posted 07 Feb 2011 Link to this post

    Hi Hassan,

    No, this is not part of the code above. Remember that to get over the issue with either a dropdown arrow, or the up/down arrows, we changed the imlementation which needs to be set in code as

    this.myRadDateTimePicker1.SetReadOnly(false, true); // not read only - show arrow 
    this.myRadDateTimePicker1.SetReadOnly(true); // read only 
    this.myRadDateTimePicker1.SetReadOnly(false, false); // not read only - show drop down arrow

    If you take the following code for the RadDateTimePicker (as above) it should be fine

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using Telerik.WinControls.UI;
      
    namespace RadControls_ReadOnly_C
    {
        class MyRadDateTimePicker : RadDateTimePicker
        {
      
      
            public MyRadDateTimePicker() 
            
            
      
      
            public override string ThemeClassName
            {
                get
                {
                    return typeof(RadDateTimePicker).FullName;
                }
            }
      
            public void SetReadOnly(Boolean IsReadOnly, Boolean ShowArrow = false)
            {
                if (IsReadOnly)
                {
                    DateTimePickerElement.Children[1].Children[1].Visibility = Telerik.WinControls.ElementVisibility.Collapsed;
                    DateTimePickerElement.TextBoxElement.TextBoxItem.ReadOnly = true;
                    base.ShowUpDown = false;
                }
                else
                {
                    DateTimePickerElement.TextBoxElement.TextBoxItem.ReadOnly = false;
                    if (ShowArrow)
                    {
                        base.ShowUpDown = true;
                    }
                    else
                    {
                        base.ShowUpDown = false;
                        DateTimePickerElement.Children[1].Children[1].Visibility = Telerik.WinControls.ElementVisibility.Visible;
                    }
                }
            }
      
            public new bool ShowUpDown
            {
                get { return base.ShowUpDown; }
            }
      
      
        }
    }

    Regards,
    Richard
  24. Chet Musialowski
    Chet Musialowski avatar
    19 posts
    Member since:
    Nov 2009

    Posted 23 Dec 2011 Link to this post

    Hello,

    I followed along with what's been done to come up with a Read Only RadDropDownList...Thanks.

    However, I'm having a problem in that the keyboard is still able to change the value (using RadControls for WinForms Q2 2011 (2011.2.11.831)).  How do I stop the keyboard ?

    Thanks,
    Chet
  25. Stefan
    Admin
    Stefan avatar
    2890 posts

    Posted 28 Dec 2011 Link to this post

    Hi Chet,

    Thank you for writing.

    I have tested the custom drop down list given in this thread with your version and I was not able to change the value of RadDropDownList. Attached you can find the application that I have used for my tests. Could you please provide me with exact information how did you manage to change the value?

    I am looking forward to your reply.

    Kind regards,
    Stefan
    the Telerik team
    Q3’10 SP1 of RadControls for WinForms is available for download; also available is the Q1'11 Roadmap for Telerik Windows Forms controls.
  26. Chet Musialowski
    Chet Musialowski avatar
    19 posts
    Member since:
    Nov 2009

    Posted 29 Dec 2011 Link to this post

    Stefan,

    Thanks for the code, it helped me find my problem.  In my case, i have DropDownStyle = RadDropDownStyle.DropDownList and that seems to allow me to type the first character of the item to get it to come up.  To get around this, I save the state of the DropDownStyle and change it to RadDropDownStyle.DropDown when in ReadOnly mode.
     
    However, in running your code, I still found I could still use the arrow keys to navigate thru the list of values even though it was "ReadOnly".  How would I go about trapping or disabling this ?

    Thanks,
    Chet
  27. Stefan
    Admin
    Stefan avatar
    2890 posts

    Posted 30 Dec 2011 Link to this post

    Hello Chet,

    Thank you for writing.

    You can prevent the selection change by subscribing to the SelectedIndexChanging event of the control and cancel the selection if you are in read only mode. Please note that this will prevent all selections and if you want to select some item programatically you will have to turn off the read only mode, select the item and turn it back on.

    I hope this helps. Let me know if you need anything else.

    Regards,
    Stefan
    the Telerik teamSP1 of Q3’11 of RadControls for WinForms is available for download (see what's new).
  28. Christian
    Christian avatar
    81 posts
    Member since:
    Aug 2008

    Posted 05 Apr 2012 Link to this post

    Hi,
    the readOnly property is also important for my project. Are there plans to implement this feature in the standard of the controls? Or do I create my own controls also in the future?
    Kind regards
    Christian
  29. Stefan
    Admin
    Stefan avatar
    2890 posts

    Posted 10 Apr 2012 Link to this post

    Hi Christian,

    Thank you for writing.

    For the time being we do not have plans for implementing such a property. The desired behavior can be easily achieved by using the attached in my previous post sample. If you do not want to inherit the control, an alternative way to achieve the same behavior is to set the DropDownStyle to DropDownList, and also, cancel the changing of the selected item in the SelectedIndexChanging event.

    I hope that you find this information useful. Let us know if you have additional questions.
     
    Greetings,
    Stefan
    the Telerik team
    RadControls for WinForms Q1'12 release is now live! Check out what's new or download a free trial >>
  30. Christian
    Christian avatar
    81 posts
    Member since:
    Aug 2008

    Posted 24 Apr 2012 Link to this post

    Hi,
    that's a little sad. It would be very helpful if a common property for all controls exist, with which the inputs can be prevented. The property 'enabled' changed unfortunately the presentation.
    Kind regards
    Christian
  31. Stefan
    Admin
    Stefan avatar
    2890 posts

    Posted 26 Apr 2012 Link to this post

    Hello Christian,

    Thank you for your feedback regarding this case.
     
    Kind regards,
    Stefan
    the Telerik team
    RadControls for WinForms Q1'12 release is now live! Check out what's new or download a free trial >>
Back to Top
UI for WinForms is Visual Studio 2017 Ready