开发者

Summing BindingList elements

This question is a follow-up from this SO post.

Basically I have a grid which contains several object called Details.

Each of them are created using the Entity Framework.

The binding is working well within the grid, even the custom properties SubTotal on each line is binded properly and everything is fin开发者_StackOverflow社区e.

The only thing I want to do know, is to have a textbox at the bottom of the window show the total.

The source of the datagrid is a BindingList, so I assigned this list as the Data Context of the TextBox, and I applied a Converter for the binding with the code as follows:

    public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
    {
       BindingList<Detail> sDets = (BindingList<Detail>)value;

       return sDets.Sum(x => x.Quantity*x.Price);
    }

However, this doesn't work. That is, when I edit the list, the changes are not updated in the text box.

I though the BindingList were supposed to handle this wasn't it?


You would need to add a change event for it to know that something is different. IMO it would be easier to forget binding here, and just handle the ListChanged event directly.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜