DropDownList - DisplayMember / ValueMember bug

2 Answers 184 Views
DropDownList
Jérôme
Top achievements
Rank 1
Iron
Iron
Iron
Jérôme asked on 20 Dec 2022, 03:08 PM

Hi,

I just noticed a terrible bug when trying to bind a list of business objects on a DropDownList :

Setting the DataSource erases both property values previously set on the designer.

Setting the DisplayMember through code works but as soon as I try to set ValueMember, it erases DisplayMember and doesn't set ValueMember either !!

        ddlLines.DataSource = lineService.GetAllLines();
        ddlLines.DisplayMember = nameof(Line.LineName);
        ddlLines.ValueMember = nameof(Line.LineId);


Here is the class :

public class Line
{
    [BrowsableAttribute(false)]
    public int LineId { get; set; }

    [DisplayName("Souche")]
    [Column(Order = 0)]
    public string LineName { get; set; }
}

This happens on a DropDownList inserted on a form and also inside a RibbonControl

Is this serious ??

Jérôme
Top achievements
Rank 1
Iron
Iron
Iron
commented on 20 Dec 2022, 03:10 PM

Using .Net 7 with Telerik for Winforms 2022.3.1109

2 Answers, 1 is accepted

Sort by
0
Jérôme
Top achievements
Rank 1
Iron
Iron
Iron
answered on 20 Dec 2022, 03:30 PM

The culprit seems to be the BrowsableAttribute on LineId property.

So I'm not able to display a list of Line on a grid (hiding LineId column), and binding the same list on a DropDownList at the same time, just because of this attribute...

0
Dess | Tech Support Engineer, Principal
Telerik team
answered on 21 Dec 2022, 09:46 AM

Hello, Jérôme,

Please have in mind that the specified DisplayMember and ValueMember properties should be publicly accessible for the data binding procedure since the properties have to be extracted. The BrowsableAttribute specifies whether a property or event should be displayed in a Properties window.

In order to properly setup the data binding, feel free to comment the attribute and give it another try.

I hope this information helps. If you need any further assistance please don't hesitate to contact me. 

Regards,
Dess | Tech Support Engineer, Principal
Progress Telerik

Love the Telerik and Kendo UI products and believe more people should try them? Invite a fellow developer to become a Progress customer and each of you can get a $50 Amazon gift voucher.

Tags
DropDownList
Asked by
Jérôme
Top achievements
Rank 1
Iron
Iron
Iron
Answers by
Jérôme
Top achievements
Rank 1
Iron
Iron
Iron
Dess | Tech Support Engineer, Principal
Telerik team
Share this question
or