tags:

views:

21

answers:

1

I'm using a VB power packs data repeater control. I need to bind a list of custom objects to labels inside the repeater. The following code works except for the Tip.User.UserName binding.

How can I bind to a property of an Inner class like Tip.User.UserName

public interface ITip
   {
    DateTime Date { get; set; }
    int Id { get; set; }
    int UserId { get; set; }
    User User { get; set; }
    Group Group { get; set; }
 }

 public interface IUser
 {
    string DisplayName { get; set; }
    string UserName { get; set; }
 }






 List<Tip>  currentTips = SearchTips(toolTxtSearch.Text, Convert.ToInt32(toolCmbTipGroups.ComboBox.SelectedValue));


            lblTipId.DataBindings.Add(new Binding("Text", currentTips, "Id"));
            lblTipUser.DataBindings.Add(new Binding("Text", currentTips, "User.UserName")); // this line doesnot work !!!


            repeater.DataSource = currentTips;
A: 

Totally depends on what error you're getting because nested property syntax should work for WinForm bindings.

As a work around (maybe the DataRepeater isn't using regular binding mechanisms?) add a property to you ITip implementation to wrap it up:

public string UsersUserName
{
    get { return User != null ? User.UserName : null; }
}

Edit: Also don't forget to implement INotifyPropertyChanged on your data objects if you want bindings to update when values do. In this case, send property changed events for both the User property of ITip implementations and the UserName of the IUser implementation.

Reddog
I think it should work. Maybe the UserName is a null-reference?
Simon
Thanks for the reply. Actually User.UserName is not null and I don't get any error but nothing is displayed on the label, to which the UserName is bound. But If I set the binding property as "User" the label shows the class name of the User class (Models.User) on the label.
Amila