How to remove DataGrid's blank row when binding to a ObservableCollection?

前端 未结 3 1557
眼角桃花
眼角桃花 2021-02-06 21:19

I\'m getting nuts here with this:

ObservableCollection list = new ObservableCollection();
dgEmployees.ItemsSource = list;
         


        
相关标签:
3条回答
  • 2021-02-06 21:51

    CanUserAddRows="False" and IsReadOnly="True" combination of both is better to ensure any additional inconveniences.

    0 讨论(0)
  • 2021-02-06 21:58

    I've got it

    on Datagrid XAML, put the attribute:

    IsReadOnly="True"
    
    0 讨论(0)
  • 2021-02-06 22:00

    The same problem persist in WPF 4.0 version of DataGrid, and it is caused by the add-new row which it shows automatically for ObservableCollection ItemsSource. Setting IsReadOnly as True it's too radical IMHO.
    I solved it by disabling CanUserAddRows property if you don't need that behavior, but you still want cells to be modified:

    CanUserAddRows="False"

    0 讨论(0)
提交回复
热议问题