Any way to show "Please Select" in databound dropdownlist

5 posts, 1 answers
  1. Tobe
    Tobe avatar
    8 posts
    Member since:
    Jul 2012

    Posted 15 Dec 2010 Link to this post

    I have a WinForms dropdown list in DropDownList Sytle that is bound to a datatable.  I've read several articles in the forums, but found nothing to either let me set the selection to blank after binding, or insert a "Please Select" selection either before or after binding.

    I've tried setting the text property and the Null Text property and these don't work either.

    Any suggestions?

  2. Richard Slade
    Richard Slade avatar
    3000 posts
    Member since:
    May 2009

    Posted 15 Dec 2010 Link to this post

    Hello,

    You would need to have the Please Select item in your datasource or, when you have the RadDropDownList in mode
    Me.RadDropDownList1.DropDownStyle = Telerik.WinControls.RadDropDownStyle.DropDownList

    then simply set
    Me.RadDropDownList1.SelectedIndex = -1

    Hope that helps
    Richard

    EDIT// SelectedIndex = -1 will set the selected record to be blank
  3. UI for WinForms is Visual Studio 2017 Ready
  4. Tobe
    Tobe avatar
    8 posts
    Member since:
    Jul 2012

    Posted 15 Dec 2010 Link to this post

    I tried that too, it doesn't work either.

    The code:

     

     

    this.ddlQuestionType.DataSource = question.GetQuestionTypeTable();

     

     

     

    this.ddlQuestionType.SelectedIndex = -1;

    Where GetQuestionTableType returns a datatable.  When the form loads, the dropdownlist still displays the first item in the datasource.

     

  5. Answer
    Richard Slade
    Richard Slade avatar
    3000 posts
    Member since:
    May 2009

    Posted 15 Dec 2010 Link to this post

    Hello,

    Please can you try this. It's just a RadDropDownList on a form.
    Dim mydatatable As New DataTable   
    mydatatable.Columns.Add("Name", Type.GetType("System.String"))
    mydatatable.Columns.Add("Id", Type.GetType("System.String"))
    Dim myrow As DataRow      
    myrow = mydatatable.NewRow
    myrow("Name") = "Richard"
    myrow("Id") = "AB1"
    mydatatable.Rows.Add(myrow)
    myrow = mydatatable.NewRow
    myrow("Name") = "Fred"
    myrow("Id") = "AB2"
    mydatatable.Rows.Add(myrow)
    Me.RadDropDownList1.DataSource = mydatatable
    Me.RadDropDownList1.DisplayMember = "Name"
    Me.RadDropDownList1.ValueMember = "Id"
    Me.RadDropDownList1.DropDownStyle = Telerik.WinControls.RadDropDownStyle.DropDownList
    Me.RadDropDownList1.Focus()
    Me.RadDropDownList1.SelectedIndex = -1

    Hope that helps
    Richard
  6. Julian Benkov
    Admin
    Julian Benkov avatar
    1135 posts

    Posted 20 Dec 2010 Link to this post

    Hi Tobe,

    You can use the solution that Richard provided, but keep in mind that setting the SelectedIndex = -1 must be executed after the binding operation and after filling the Data Adapter of the bound DataTable object in your case.

    All the best,
    Julian Benkov
    the Telerik team
    Check out the Q1 2011 Roadmap for Telerik Controls for Windows Forms.
Back to Top
UI for WinForms is Visual Studio 2017 Ready