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

Promlem with adding a blank row.

4 Answers 106 Views
DropDownList
This is a migrated thread and some comments may be shown as answers.
Andy Green
Top achievements
Rank 2
Andy Green asked on 14 May 2015, 12:31 PM

Hi

This is my code to bind data to a RadComboBox:

With ddlFutureCode
.Items.Clear()
.Items.Add(New RadComboBoxItem("", 0))
.DataSource = l_ds.Tables(1)
.DataTextField = "Name"
.DataValueField = "Value"
.DataBind()
End With

 

It works fine, and places a blank row at the top if no selection is to be made. However:

With this code )setting a default tot blank row disappears so if the default value isn't required ist not possible to select a blank row.

With ddlFutureCode
 .Items.Clear()
.Items.Add(New RadComboBoxItem("", 0))
.DataSource = l_ds.Tables(1)
.DataTextField = "Name"
.DataValueField = "Value"
.DataBind()

End With
ddlFutureCode.SelectedItem.Text = FutureCode

 Andy

 

 

4 Answers, 1 is accepted

Sort by
0
Aneliya Petkova
Telerik team
answered on 18 May 2015, 10:34 AM
Hi Andy,

Please try the sample page I attached to this thread and modify it in order to show me the issue you are facing, because I am not sure I understand you correctly. Here you may find a video demonstrating how the RadComboBox is behaving at my side.

Regards,
Aneliya Petkova
Telerik
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 Feedback Portal and vote to affect the priority of the items
0
Andy Green
Top achievements
Rank 2
answered on 18 May 2015, 10:55 AM

Hi Aneliya

If you change your code to match this you will see the problem:

With ddlFutureCode
.Items.Clear()
.Items.Add(New RadComboBoxItem("", 0))
.Items.Add(New RadComboBoxItem("1", 1))
.Items.Add(New RadComboBoxItem("FutureCode", 2))
.DataBind()
End With
'ddlFutureCode.SelectedIndex = 2
ddlFutureCode.SelectedItem.Text = "FutureCode"

form1.Controls.Add(ddlFutureCode)

I'm not using Selected Index as I wont know the index values of the required field in the dataset.

Andy

 

0
Accepted
Aneliya Petkova
Telerik team
answered on 19 May 2015, 10:03 AM
Hi Andy,

Could you please explain in more details what exactly you need to achieve, because I am still not sure I understand you correctly?

Please note that when you are using the code below, you are overriding the Text of the Selected Item - in your case this is the first item in the RadCombomboBox(with the empty text):
ddlFutureCode.SelectedItem.Text = "FutureCode"

If you want to select an item from the RadComboBox by its Text, you can use the following code instead:
ddlFutureCode.FindItemByText("FutureCode").Selected = True

So the changed VB code should look like the following:
Dim ddlFutureCode As New RadComboBox
 
With ddlFutureCode
    .Items.Clear()
    .Items.Add(New RadComboBoxItem("", 0))
    .Items.Add(New RadComboBoxItem("1", 1))
    .Items.Add(New RadComboBoxItem("FutureCode", 2))
    .DataBind()
End With
 
ddlFutureCode.FindItemByText("FutureCode").Selected = True
 
form1.Controls.Add(ddlFutureCode)


Regards,
Aneliya Petkova
Telerik
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 Feedback Portal and vote to affect the priority of the items
0
Andy Green
Top achievements
Rank 2
answered on 19 May 2015, 12:57 PM

Thanks Aneliya

This is what I was missing:

ddlFutureCode.FindItemByText("FutureCode").Selected = True

Andy

Tags
DropDownList
Asked by
Andy Green
Top achievements
Rank 2
Answers by
Aneliya Petkova
Telerik team
Andy Green
Top achievements
Rank 2
Share this question
or