NullText Property doesn't work in RadDropDown

9 posts, 0 answers
  1. Nick Gebbett
    Nick Gebbett avatar
    13 posts
    Member since:
    May 2010

    Posted 28 Sep 2010 Link to this post

    this.RadDropDownList_LocationType.DropDownStyle = Telerik.WinControls.RadDropDownStyle.DropDownList;
    this.RadDropDownList_LocationType.Location = new System.Drawing.Point(4, 4);
    this.RadDropDownList_LocationType.Name = "RadDropDownList_LocationType";
    this.RadDropDownList_LocationType.NullText = "Please Select";
    this.RadDropDownList_LocationType.Size = new System.Drawing.Size(123, 18);
    this.RadDropDownList_LocationType.TabIndex = 0;
    When I Use RadComboBox instead RadDropDown property works.
  2. Emanuel Varga
    Emanuel Varga avatar
    1336 posts
    Member since:
    May 2010

    Posted 29 Sep 2010 Link to this post

    Hello Alexander,

    Yes, this is true, when the DropDownStyle is set to DropDownList the null text is no longer visible, but the Text property should work fine as a NullText until a fix will be issued.

    Best Regards,
    Emanuel Varga
  3. UI for WinForms is Visual Studio 2017 Ready
  4. Peter
    Admin
    Peter avatar
    1148 posts

    Posted 01 Oct 2010 Link to this post

    Indeed, Emanuel is correct. 
     
    By design the text defined by the NullText property is displayed in the editor's input box when the editor is not in DropDownList mode. We actually set  RadTextBox's Null Text property but in DropDownList mode this textbox is not visible. This is why you can't see the Null text.
     
    I hope this explanation clarifies the situation.

    Sincerely yours,

    Peter
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
  5. Nick Gebbett
    Nick Gebbett avatar
    13 posts
    Member since:
    May 2010

    Posted 05 Oct 2010 Link to this post

    I definitely not understand why this is designed and how to show user "Please select" option when SelectedValue = null
  6. Emanuel Varga
    Emanuel Varga avatar
    1336 posts
    Member since:
    May 2010

    Posted 06 Oct 2010 Link to this post

    Hello Alexander,

    The solution I've offered would do the trick, like i said, assign to the Text property the text you want to show when no item is selected, after the user selects something from the list, that text will no longer be visible. One downside of that is the fact that it's not a faded text and it's not italic.

    In my point of view, if and until that NullText property will work for the DropDownList style, this is the way to go (or create a dummy first element in your collection, handle the selected index changed event, and when new index != 0 remove that element from the collection)

    Hope this helps, if you have any other questions, please let me know,

    Best Regards,
    Emanuel Varga
  7. Nick Gebbett
    Nick Gebbett avatar
    13 posts
    Member since:
    May 2010

    Posted 07 Oct 2010 Link to this post

    In case of my application it is not an option to use DropDownStyle.DropDown
    So you are right, the only way I see is to create a dummy objects in all DropDowns. Thank you.
    But it is not useful.

    I'm trying to understand why RadDropDown works like that. What so bad will happene if RadDropDown.NullText shows the string I need in DropDownList mode? =)
  8. Emanuel Varga
    Emanuel Varga avatar
    1336 posts
    Member since:
    May 2010

    Posted 07 Oct 2010 Link to this post

    Hello Alexander,

    I completely agree with you that the null text should be shown whenever there is no item selected in a DropDownList, but until they will fix this, i would suggest you try this workaround:
    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Linq;
    using System.Text;
    using System.Windows.Forms;
    using Telerik.WinControls.UI;
     
    namespace TestDropDownListNullText
    {
         
        public partial class Form1 : Form
        {
            public RadDropDownList radDropDownList1;
            public Form1()
            {
                InitializeComponent();
                this.Load += new EventHandler(Form1_Load);
            }
     
            void Form1_Load(object sender, EventArgs e)
            {
                radDropDownList1 = new RadDropDownList();
                radDropDownList1.Dock = DockStyle.Top;
     
                this.Controls.Add(radDropDownList1);
     
                radDropDownList1.DropDownStyle = Telerik.WinControls.RadDropDownStyle.DropDownList;
                radDropDownList1.PopupClosing += new RadPopupClosingEventHandler(radDropDownList1_PopupClosing);
                radDropDownList1.DataSource = new TestsCollection(10);
                radDropDownList1.DisplayMember = "Name";
                radDropDownList1.Text = "Please select something...";
            }
     
            void radDropDownList1_PopupClosing(object sender, RadPopupClosingEventArgs args)
            {
                if (string.IsNullOrEmpty(radDropDownList1.Text))
                {
                    radDropDownList1.Text = "Please select something...";
                }
            }
        }
     
        #region Business Objects
     
        public class Test
        {
            public int Id
            {
                get;
                set;
            }
     
            public string Name
            {
                get;
                set;
            }
     
            public Test(int id, string name)
            {
                this.Id = id;
                this.Name = name;
            }
        }
     
        public class TestsCollection : List<Test>
        {
            public TestsCollection(int noItems)
            {
                for (int i = 0; i < noItems; i++)
                {
                    this.Add(new Test(i, "test" + i));
                }
            }
        }
     
        #endregion Business Objects
    }

    Hope this helps, if you have any other questions or comments, please let me know,

    Best Regards,
    Emanuel Varga
  9. François
    François  avatar
    1 posts
    Member since:
    Feb 2011

    Posted 30 Nov 2011 Link to this post

    Is this feature in telerik roadmap? To see nulltext with null value as first item when  DropDownStyle is set to DropDownList?
  10. Peter
    Admin
    Peter avatar
    1148 posts

    Posted 05 Dec 2011 Link to this post

    Hello Alexander,

    Thanks for writing back.

    You can easily workaround this by setting the Text property instead of NullText property in this mode.
    Please refer to the attached project. Also, you can use the Emanuel's solution.

    I hope this helps.

    All the best,
    Peter
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
Back to Top
UI for WinForms is Visual Studio 2017 Ready