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

DropDownList Control Bugs

5 Answers 172 Views
DropDownList
This is a migrated thread and some comments may be shown as answers.
Jason Gaylord
Top achievements
Rank 1
Jason Gaylord asked on 11 Feb 2011, 09:11 PM
I noticed a few issues with the DropDownList control. 

1) When using HTML, if the DropDownList's DropDownStyle is set to DropDown, the HTML source is displayed as the text. See the attached screenshot for an example of this.

2) When using autocomplete, I cannot get the autocomplete to work on part of the item (the first part is a number) and have it select the item appropriately based on the value. It doesn't seem like it works. Again, see the second screenshot. Here's a code snippet:

Public Class Form1
    Private Sub Form1_Load() Handles Me.Load
        Dim x As New ItemModel
        RadDropDownList1.DataSource = x.ListItems
        RadDropDownList1.ValueMember = "ItemNumber"
        RadDropDownList1.AutoCompleteMode = AutoCompleteMode.SuggestAppend
        RadDropDownList1.AutoCompleteValueMember = "ItemNumber"
    End Sub
  
    Private Sub radDropDownList1_ItemDataBound(ByVal sender As Object, ByVal args As Telerik.WinControls.UI.ListItemDataBoundEventArgs) Handles RadDropDownList1.ItemDataBound
        Dim view As DataRowView = CType(args.NewItem.DataBoundItem, DataRowView)
        args.NewItem.Text = "<html><b>" & view("ItemNumber") & " • " & view("ItemName") & "</b><br/>" & view("Description") & "</html>"
        args.NewItem.Height = 40
    End Sub
  
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        MessageBox.Show(RadDropDownList1.SelectedValue)
    End Sub
End Class

5 Answers, 1 is accepted

Sort by
0
Ivan Todorov
Telerik team
answered on 16 Feb 2011, 01:42 PM
Hello Jason,

Thank you for writing.

The reason for the two issues is one: by handling the ItemDataBound event you change the logical item's data and add the HTML tags to it. That is why the displayed text contains the tags. The auto-complete will not work because, it also searches through the tags. The proper way to achieve the desired behavior is by handling the VisualItemFormatting event:
Private Sub radDropDownList1_VisualListItemFormatting(sender As Object, args As VisualItemFormattingEventArgs)
Handles radDropDownList1.VisualItemFormatting
    Dim view As ItemView = TryCast(args.VisualItem.Data.DataBoundItem, ItemView)
    If view Is Nothing Then
        Return
    End If
 
    args.VisualItem.Text = (("<html><b>" + view.Number & " • ") + view.Name & "</b><br/>") + view.Description & "</html>"
    args.VisualItem.Data.Height = 40
End Sub

I hope this will help you. If you need further help, do not hesitate to contact me.

Regards,
Ivan Todorov
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
Jason Gaylord
Top achievements
Rank 1
answered on 16 Feb 2011, 03:57 PM
Ivan,

With all due respect, your documentation is incorrect.

1) From the PDF that you download on your demos page, it recommends using a RadListBox or RadComboBox. However, according to your site, this control was depricated in Q2 2010 in leiu of the RadListControl and the RadDropDownList.

2) Based on your suggestion, your tutorial is incorrect on the site. It shows an example using the ItemDataBound event.

We should get bonus points for this. :)

Also, I did get this to work using a combination of your response and my code. This is what I ended up with.

Private Sub radDropDownList1_VisualListItemFormatting(ByVal sender As Object, ByVal args As VisualItemFormattingEventArgs) Handles RadDropDownList1.VisualListItemFormatting
    Dim view As DataRowView = TryCast(args.VisualItem.Data.DataBoundItem, DataRowView)
    If view Is Nothing Then
        Return
    End If
    args.VisualItem.Text = "<html><b>" & view("SubscriberNumber") & " • " & view("SubscriberName") & "</b><br/>" & view("Location") & "</html>"
    args.VisualItem.Data.Height = 40
End Sub

Jason
0
Nikolay
Telerik team
answered on 16 Feb 2011, 04:30 PM
Hello Jason,

Thank you for writing back.

In regards to your first point, as I replied in the support ticket that you have opened, this is a known issue and we are currently working on updating the whole Step-by-step tutorial.

The answer that my colleague Ivan has given concerns the RadDropDownList while the documentation article is about RadListControl where the ItemDataBound event can be used. We will include an article for RadDropDownList where the VisualListItemFormatting event is handled. Your Telerik points have been updated for the feedback.

I am glad to hear that all is working fine now. If you have additional questions, feel free to write back.

Best wishes,
Nikolay
the Telerik team
0
Jason Gaylord
Top achievements
Rank 1
answered on 16 Feb 2011, 04:39 PM
Then my gripe isn't just the documentation, it's the lack of consistancy. Whatever you use for one control should be the same for others if they implement the same event names. That would be like having two cars and not properly explaining that the older models must use a key to start the vehicle and the new cars use a push button. Make sense?
0
Nikolay
Telerik team
answered on 17 Feb 2011, 08:26 AM
Hello Jason,

I understand your point and this is why as I mentioned we will update the documentation for RadDropDownList accordingly. We will also make a note about the usage of ItemDataBound event and VisualListItemFormatting event in the documentation of RadListControl.

Although RadDropDownList and RadListControl share the same API for your convenience, their behavior and purpose are different. As a consequence, one event can be useful for one control while you may not want to use the same event for the other control, because of the specifics of this control and the overall behavior that you will get at the end. In our specific case ItemDataBound is useful only for RadListControl while VIsualListItemFormatting is useful for both controls and this will be clearly stated in the documentation for your convenience.

Best wishes,
Nikolay
the Telerik team
Tags
DropDownList
Asked by
Jason Gaylord
Top achievements
Rank 1
Answers by
Ivan Todorov
Telerik team
Jason Gaylord
Top achievements
Rank 1
Nikolay
Telerik team
Share this question
or