WPF datagrid empty row at bottom

后端 未结 5 791
忘掉有多难
忘掉有多难 2020-12-23 15:51

I bind my datagrid using

//fill datagrid
public DataTable GameData
{
    get
    {
        DataSet ds = new DataSet();
        FileStream fs = new FileStream         


        
相关标签:
5条回答
  • 2020-12-23 16:00

    It also works with the attribute:

    IsReadOnly="true"
    
    0 讨论(0)
  • 2020-12-23 16:09

    Sounds like you probably have CanUserAddRows set to true for the DataGrid. Just add

    CanUserAddRows="false"
    

    to the XAML.

    0 讨论(0)
  • 2020-12-23 16:16

    Though the OP was asking how to REMOVE the empty row, the title isn't specific, and this article appeared in my search while trying to figure out how to ADD the empty row. I found that, for the empty row to appear, it not only needs to have CanUserAddRows="True" but the ItemsSource needs to have a default constructor public MyClass () { }.

    0 讨论(0)
  • 2020-12-23 16:17

    If your backing collection that implements IEditableCollectionView returns true from its CanAddNew method, the DataGrid will assume that is what you want to do.

    There's a good overview here:Overview of the editing features in the WPF DataGrid

    0 讨论(0)
  • 2020-12-23 16:24

    If you're creating DataGrid on-the-fly through Source Code...

    DataGrid grid = new DataGrid();
    
    grid.CanUserAddRows = false;
    
    //... 
    grid.AutoGenerateColumns = false;
    grid.Margin = new Thickness(10,20,10,10);
    grid.VerticalAlignment = VerticalAlignment.Top;
    grid.ItemsSource = //... and so on
    
    0 讨论(0)
提交回复
热议问题