开发者

Binding WPF4 Datagrid to Empty Collection

I have a collection of objects which I am trying to bind to a DataGrid. When the collection has a lot of objects in it, it works fine. When the collection is empty, however, I see a blank row in the DataGrid, however, I cannot edit it. When I bind it to a collection which has an empty list, then two rows appear, and it is possible to edit the second row with the first empty, even though I have validation. I have tried both an ordinary List<>, and an开发者_如何转开发 ObservableCollection<>.

How can I make it so that either the DataGrid can enter into an empty list, or that the DataGrid won't let the user enter into the second blank row?


For what its worth, I did figure out what my problem was. Well, I fixed the glitch, but I am not at all sure why it worked.

In the Binding field of the DataGrid, I had Mode=TwoWay on. I thought this was needed, as I wanted the grid to go back to the data, and vice versa. Turns out, removing this fixed the problem.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜