Remove "Editable Row"

Aug 21, 2008 at 5:03 PM
I have successfully created my DataGrid and have data binding and styles/templates already set up, however there is one thing I can not figure out.  After I set up each column 's DataTemplate (using TextBlock's so they're not editable) I still always have an extra blank row at the bottom of my datagrid. 

I tried turning off "CanUserAddRows" but to no avail.  I fell like there should be a property called "IsEditable" that I can turn off.  Does anyone know how to remove this extra row so that I'm only showing the data that I am binding to?
Aug 21, 2008 at 5:55 PM
In the final version of the DataGrid there will be an available property, IsReadOnly that can accomplish what you are trying to do.  In the meantime what you can do is set the NewItemPlaceholderPosition to None which will remove that extra row.  Something like this:



view = CollectionViewSource.GetDefaultView(DataGrid_Standard.ItemsSource);
iecv = (
iecv.NewItemPlaceholderPosition =


Aug 21, 2008 at 5:59 PM
Also, setting CanUserAddRows to false should remove the NewItemPlaceholder but as you've seen it doesn't.  This is a known issue and should be fixed in the final version.
Aug 21, 2008 at 7:50 PM
Thanks, that worked great!

Here's what ended up working with VB:

Imports System.ComponentModel
 Private Sub MyWindow_Loaded(ByVal sender As Object, ByVal e As System.Windows.RoutedEventArgs) Handles Me.Loaded
        Dim view As ICollectionView = CollectionViewSource.GetDefaultView(DataGrid_Standard.ItemsSource)
        Dim iecv As IEditableCollectionView = CType(view, IEditableCollectionView)
        iecv.NewItemPlaceholderPosition = NewItemPlaceholderPosition.None
End Sub
Aug 22, 2008 at 3:13 PM


Thanks. Glad I read this because after I did I noticed my grid was doing the same thing with an empty row at the bottom. I also am using Data Templates to keep the cells read only. Weird thing is I first tried setting (CanUserAddRows="False") in my Xaml and this turned off the empty row at the bottom. I didn't have to do anything with NewItemPlaceholderPosition. Maybe because I am binding to a DataSet table?

One thing about keeping the cells non-edit. I have SelectionUnit="FullRow" and everything works great but I can't get rid of the cell border when the user highlights that cell's row.  Any ideas?


Sep 11, 2008 at 12:00 AM
Thanks for the workaround.

I am using the DataGrid inside a DataTemplate.  I have found that binding to the Initialized event works pretty well in this case:
<dg:DataGrid Initialized="DataGrid_Initialized" ItemsSource="{Binding Path=Users}" AutoGenerateColumns="False" CanUserAddRows="False" CanUserDeleteRows="False" >

private void DataGrid_Initialized(object sender, EventArgs e)
            ICollectionView view = CollectionViewSource.GetDefaultView(((Microsoft.Windows.Controls.DataGrid)sender).ItemsSource);
            var iecv = (IEditableCollectionView)view;
            iecv.NewItemPlaceholderPosition = NewItemPlaceholderPosition.None;
Oct 13, 2008 at 11:21 AM
Edited Oct 13, 2008 at 12:51 PM
Here's the fix i'm using, it may be helpful to someone.

public class DataGridFix : DataGrid
    static DataGridFix()

        DataGridFix.ItemsSourceProperty.OverrideMetadata(typeof(DataGridFix), new FrameworkPropertyMetadata(new PropertyChangedCallback(ItemsSourcePropertyChanged)));
        DataGridFix.CanUserAddRowsProperty.OverrideMetadata(typeof(DataGridFix), new FrameworkPropertyMetadata(new PropertyChangedCallback(ItemsSourcePropertyChanged)));


    private static void ItemsSourcePropertyChanged(DependencyObject target, DependencyPropertyChangedEventArgs args)
        var dg = (Microsoft.Windows.Controls.DataGrid)target;
        if (!dg.CanUserAddRows)

            var view = CollectionViewSource.GetDefaultView(((Microsoft.Windows.Controls.DataGrid)target).ItemsSource);
            var iecv = (IEditableCollectionView)view;
            iecv.NewItemPlaceholderPosition = NewItemPlaceholderPosition.None;