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?
I've tried setting the text property and the Null Text property and these don't work either.
Any suggestions?
4 Answers, 1 is accepted
0
Richard Slade
Top achievements
Rank 2
answered on 15 Dec 2010, 05:50 PM
Hello,
You would need to have the Please Select item in your datasource or, when you have the RadDropDownList in mode
then simply set
Hope that helps
Richard
EDIT// SelectedIndex = -1 will set the selected record to be blank
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
0
Tobe
Top achievements
Rank 1
answered on 15 Dec 2010, 05:56 PM
I tried that too, it doesn't work either.
The code:
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.
0
Accepted
Richard Slade
Top achievements
Rank 2
answered on 15 Dec 2010, 06:08 PM
Hello,
Please can you try this. It's just a RadDropDownList on a form.
Hope that helps
Richard
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
0
Hi Tobe,
Julian Benkov
the Telerik team
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.