Binding to a Tag in a listBox

2 posts, 0 answers
  1. Scott Gross
    Scott Gross  avatar
    15 posts
    Member since:
    Feb 2009

    Posted 18 Nov 2007 Link to this post

    I have a busniess Object that I am currently binding to the a RadListBox.

    Is there a way to set the Tag of the RadListBoxItem to the BO while binding?

    If not does anyone have a better suggestion the a foreach loop and comparing the id (from the value field of the bind) to get the BO of the selection?

    Thank you
  2. Angel
    Admin
    Angel avatar
    121 posts

    Posted 19 Nov 2007 Link to this post

    Hello Scott Gross,

    The ItemDataBound event of RadListBoxElement is raised when a new RadListBoxItem is added, while binding the list box. This is a convenient place to put the code you need to get the job done. Here is an example showing how to subscribe for that event:

    C#:
    RadListBoxElement listBoxElement = (RadListBoxElement)this.radListBox1.RootElement.Children[0];
    listBoxElement.ItemDataBound += new ItemDataBoundEventHandler(onItemDataBound);

    VB:
    Dim listBoxElement As RadListBoxElement = CType(Me.radListBox1.RootElement.Children(0), RadListBoxElement)
    AddHandler listBoxElement.ItemDataBound, AddressOf onItemDataBound


    The onItemDataBound event handler receives in its event argument a RadListBoxItem and its corresponding data object. This makes it easy for you to set the property Tag to whatever you need.

    If you have any additional questions, please contact us.

    Kind regards,
    Angel
    the Telerik team

    Instantly find answers to your questions at the new Telerik Support Center
  3. UI for WinForms is Visual Studio 2017 Ready
Back to Top