This is a migrated thread and some comments may be shown as answers.

Read Only for all editors

33 Answers 551 Views
DropDownList
This is a migrated thread and some comments may be shown as answers.
DoomerDGR8
Top achievements
Rank 2
Iron
Iron
Iron
DoomerDGR8 asked on 31 Jan 2011, 11:17 AM
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.

33 Answers, 1 is accepted

Sort by
0
Richard Slade
Top achievements
Rank 2
answered on 31 Jan 2011, 01:45 PM
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
0
DoomerDGR8
Top achievements
Rank 2
Iron
Iron
Iron
answered on 31 Jan 2011, 02:49 PM
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?
0
Accepted
Richard Slade
Top achievements
Rank 2
answered on 31 Jan 2011, 03:12 PM
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
0
DoomerDGR8
Top achievements
Rank 2
Iron
Iron
Iron
answered on 31 Jan 2011, 05:20 PM
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;
    }
 
  }
 
}
0
Accepted
Richard Slade
Top achievements
Rank 2
answered on 31 Jan 2011, 05:29 PM
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
0
DoomerDGR8
Top achievements
Rank 2
Iron
Iron
Iron
answered on 31 Jan 2011, 05:31 PM
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;
  }
}
0
Accepted
Richard Slade
Top achievements
Rank 2
answered on 31 Jan 2011, 05:35 PM
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
0
DoomerDGR8
Top achievements
Rank 2
Iron
Iron
Iron
answered on 31 Jan 2011, 05:51 PM
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.
0
DoomerDGR8
Top achievements
Rank 2
Iron
Iron
Iron
answered on 31 Jan 2011, 05:53 PM
BTW, I love this thread.
0
Richard Slade
Top achievements
Rank 2
answered on 31 Jan 2011, 06:27 PM
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
0
DoomerDGR8
Top achievements
Rank 2
Iron
Iron
Iron
answered on 31 Jan 2011, 06:47 PM
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!
0
Richard Slade
Top achievements
Rank 2
answered on 31 Jan 2011, 07:43 PM
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.
0
Stefan
Telerik team
answered on 03 Feb 2011, 12:35 PM
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.
0
DoomerDGR8
Top achievements
Rank 2
Iron
Iron
Iron
answered on 03 Feb 2011, 12:47 PM
Please elaborate.
0
DoomerDGR8
Top achievements
Rank 2
Iron
Iron
Iron
answered on 07 Feb 2011, 10:11 AM
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?
0
Richard Slade
Top achievements
Rank 2
answered on 07 Feb 2011, 10:14 AM
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
0
DoomerDGR8
Top achievements
Rank 2
Iron
Iron
Iron
answered on 07 Feb 2011, 12:34 PM
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.
0
Richard Slade
Top achievements
Rank 2
answered on 07 Feb 2011, 12:43 PM
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
0
Accepted
Richard Slade
Top achievements
Rank 2
answered on 07 Feb 2011, 12:53 PM
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
0
DoomerDGR8
Top achievements
Rank 2
Iron
Iron
Iron
answered on 07 Feb 2011, 01:15 PM
Ok. This DateTime code you gave above, where is the event?

private event EventHandler<EventArgs> ReadOnlyChanged;

Or there is no need of it anymore?
0
Accepted
Richard Slade
Top achievements
Rank 2
answered on 07 Feb 2011, 01:20 PM
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
0
Chet Musialowski
Top achievements
Rank 1
answered on 23 Dec 2011, 09:39 PM
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
0
Stefan
Telerik team
answered on 28 Dec 2011, 03:08 PM
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.
0
Chet Musialowski
Top achievements
Rank 1
answered on 29 Dec 2011, 04:04 PM
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
0
Stefan
Telerik team
answered on 30 Dec 2011, 04:39 PM
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).
0
Christian
Top achievements
Rank 1
answered on 05 Apr 2012, 10:43 AM
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
0
Stefan
Telerik team
answered on 10 Apr 2012, 08:51 AM
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 >>
0
Christian
Top achievements
Rank 1
answered on 24 Apr 2012, 07:08 AM
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
0
Stefan
Telerik team
answered on 26 Apr 2012, 03:07 PM
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 >>
0
Lasse
Top achievements
Rank 1
answered on 19 Aug 2012, 08:00 PM
I have to agree with Christian that the best solution would be if you added the functionality to your controls.

Inheriting your controls and writing code as described previously in this thread is not desirable if you want to maintain a bug-free application.

I would have to test all Telerik controls in my App whenever I update the Telerik components, to ensure that you guys haven't changed anything vital in your controls, and that my App continues to work as intended.

IMHO it really is NOT an option to start messing with inheriting your controls to achieve a simple feature as a readonly property.

It makes no sense to me that eg. a RadCheckBox does not display its checked state, just because the control is not Enabled...!? In my opinion that is a bug, also considering that the standard CheckBox controls does show its checked state correctly when not Enabled.

In fact it makes no sense that any control would not show its value correctly, when not Enabled.

Since the purpose of using Telerik controls in stead of default controls is to have more features and functionality, I would expect precisely that - not restrictions in functionality.
0
Stefan
Telerik team
answered on 22 Aug 2012, 07:38 AM
Hello,

Thank you for your feedback regarding this matter. There is a feature request added for this functionality. Feel free to add your vote for it here: http://www.telerik.com/support/pits.aspx#/details/Issue=10738.

In regards to the check box this is also a known limitation and a case for it also exists: http://www.telerik.com/support/pits.aspx#/details/Issue=12254.

Inheriting a control does not mean that a bug will be introduced. Especially in cases like this one. If you have any doubts regarding some functionality, you can always open a support ticket with your control and ask for advice.

I agree that the check box issue is quite unpleasant. Unfortunately the issue is deep in our framework and addressing it is not an easy task. In regards to the read only state for a drop down list, such feature differs from the control semantic. However, due to the interest shown in this thread, a feature request is created. 

Feel free to add your votes for those cases since this increases their priority among the other tasks. 

I hope that you find this reply useful. 
 
All the best,
Stefan
the Telerik team
RadControls for WinForms Q2'12 release is now live! Check out what's new or download a free trial >>
0
Francois
Top achievements
Rank 1
answered on 30 Aug 2013, 03:48 PM
Sorry to revive an old thread, but for the RadDropdownList, I'm currently using this code and it seems to work well without subscribing to any event :


/// <summary>
/// Note : The value of 'SelectNextOnDoubleClick' is set to 'False' in all cases.
/// </summary>
/// <param name="ddl"></param>
/// <param name="readOnly"></param>
public static void SetReadOnly(this RadDropDownList ddl, bool readOnly)
{
    ddl.DropDownListElement.ArrowButton.Enabled = !readOnly; // Helps the user identify that the control is ReadOnly
    ddl.SelectNextOnDoubleClick = false;
    ddl.Popup.Enabled = !readOnly;
  
    // For this mode, prevent modification with the keyboard
    if (ddl.DropDownStyle == RadDropDownStyle.DropDown)
    {
        ddl.DropDownListElement.TextBox.TextBoxItem.ReadOnly = readOnly;
        ddl.EnableMouseWheel = !readOnly;
    }
}

EDIT:  I have added the 'ddl.EnableMouseWheel' line, because you could change the value by scrolling with the mouse wheel, 
0
Stefan
Telerik team
answered on 03 Sep 2013, 09:56 AM
Hello Francois,

Thank you for sharing your code with the community. I am sure someone will benefit from it.
 
Regards,
Stefan
Telerik
TRY TELERIK'S NEWEST PRODUCT - EQATEC APPLICATION ANALYTICS for WINFORMS.
Learn what features your users use (or don't use) in your application. Know your audience. Target it better. Develop wisely.
Sign up for Free application insights >>
Tags
DropDownList
Asked by
DoomerDGR8
Top achievements
Rank 2
Iron
Iron
Iron
Answers by
Richard Slade
Top achievements
Rank 2
DoomerDGR8
Top achievements
Rank 2
Iron
Iron
Iron
Stefan
Telerik team
Chet Musialowski
Top achievements
Rank 1
Christian
Top achievements
Rank 1
Lasse
Top achievements
Rank 1
Francois
Top achievements
Rank 1
Share this question
or