Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4064760
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T15:53:49+00:00 2026-05-20T15:53:49+00:00

I need to hide the last row with some text (say click to insert

  • 0

I need to hide the last row with some text (say click to insert new row) and when user clicks the text will dissaper and row will be added. and the text will apper move down to add another row.
it basically text block is overlapping on last row of Datagridview.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-20T15:53:50+00:00Added an answer on May 20, 2026 at 3:53 pm

    See the following link, it does exactly that
    http://blogs.msdn.com/b/vinsibal/archive/2008/11/05/wpf-datagrid-new-item-template-sample.aspx

    Update 2

    Modified the ControlTemplate a bit and uploaded my sample project here:
    http://www.mediafire.com/download.php?ea519xwbc53i91i

    enter image description here

    Update

    Adding the necessary steps from the link

    Xaml

    <DataGrid x:Name="dataGrid"
              LoadingRow="dataGrid_LoadingRow"
              UnloadingRow="dataGrid_UnloadingRow"
              RowEditEnding="dataGrid_RowEditEnding"
              ...>
        <DataGrid.Resources>
            <ControlTemplate x:Key="NewRow_ControlTemplate" TargetType="{x:Type DataGridRow}">
                <Border x:Name="DGR_Border" Background="{TemplateBinding Background}" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}" SnapsToDevicePixels="True">
                    <SelectiveScrollingGrid>
                        <TextBlock Text="Click here to add a new item." Grid.Column="1"/>
                    </SelectiveScrollingGrid>
                </Border>
            </ControlTemplate>
        </DataGrid.Resources>
        <DataGrid.RowStyle>
            <Style TargetType="DataGridRow">
                <EventSetter Event="MouseLeftButtonDown" Handler="Row_MouseLeftButtonDown" />
            </Style>
        </DataGrid.RowStyle>
        <!--...-->
    </DataGrid>
    

    Code behind

    ControlTemplate _defaultRowControlTemplate = null;
    ControlTemplate _newRowControlTemplate = null;
    private void dataGrid_LoadingRow(object sender, DataGridRowEventArgs e)
    {
        if (_defaultRowControlTemplate == null)
        {
            _defaultRowControlTemplate = e.Row.Template;
        }
        if (_newRowControlTemplate == null)
        {
            _newRowControlTemplate = dataGrid.FindResource("NewRow_ControlTemplate") as ControlTemplate;
        }
        if (e.Row.Item == CollectionView.NewItemPlaceholder)
        {
            e.Row.Template = _newRowControlTemplate;
            e.Row.UpdateLayout();
        }
    }
    private void dataGrid_UnloadingRow(object sender, DataGridRowEventArgs e)
    {
        if (e.Row.Item == CollectionView.NewItemPlaceholder && e.Row.Template != _defaultRowControlTemplate)
        {
            e.Row.Template = _defaultRowControlTemplate;
            e.Row.UpdateLayout();
        }
    }
    private void Row_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
    {
        DataGridRow row = sender as DataGridRow;
        if (row.Item == CollectionView.NewItemPlaceholder && row.Template == _newRowControlTemplate)
        {
            // for a new row update the template and open for edit
            row.Template = _defaultRowControlTemplate;
            row.UpdateLayout();
            dataGrid.CurrentItem = row.Item;
            DataGridCell cell = DataGridHelper.GetCell(dataGrid, dataGrid.Items.IndexOf(row.Item), 0);
            cell.Focus();
            dataGrid.BeginEdit();
        }
    }
    private void dataGrid_RowEditEnding(object sender, DataGridRowEditEndingEventArgs e)
    {
        IEditableCollectionView iecv = CollectionViewSource.GetDefaultView((sender as DataGrid).ItemsSource) as IEditableCollectionView;
        if (iecv.IsAddingNew)
        {
            // need to wait till after the operation as the NewItemPlaceHolder is added after
            Dispatcher.Invoke(new DispatcherOperationCallback(ResetNewItemTemplate), DispatcherPriority.ApplicationIdle, dataGrid);
        }
    }
    private object ResetNewItemTemplate(object arg)
    {
        DataGridRow row = DataGridHelper.GetRow(dataGrid, dataGrid.Items.Count - 1);
        if (row.Template != _newRowControlTemplate)
        {
            row.Template = _newRowControlTemplate;
            row.UpdateLayout();
        }
        return null;
    }
    

    DataGridHelper

    public static class DataGridHelper
    {
        public static DataGridCell GetCell(DataGrid dataGrid, int row, int column)
        {
            DataGridRow rowContainer = GetRow(dataGrid, row);
            if (rowContainer != null)
            {
                DataGridCellsPresenter presenter = GetVisualChild<DataGridCellsPresenter>(rowContainer);
                if (presenter == null)
                {
                    dataGrid.ScrollIntoView(rowContainer, dataGrid.Columns[column]);
                    presenter = GetVisualChild<DataGridCellsPresenter>(rowContainer);
                }
                // try to get the cell but it may possibly be virtualized
                DataGridCell cell = (DataGridCell)presenter.ItemContainerGenerator.ContainerFromIndex(column);
                if (cell == null)
                {
                    // now try to bring into view and retreive the cell
                    dataGrid.ScrollIntoView(rowContainer, dataGrid.Columns[column]);
                    cell = (DataGridCell)presenter.ItemContainerGenerator.ContainerFromIndex(column);
                }
                return cell;
            }
            return null;
        }
        public static DataGridRow GetRow(DataGrid dataGrid, int index)
        {
            DataGridRow row = (DataGridRow)dataGrid.ItemContainerGenerator.ContainerFromIndex(index);
            if (row == null)
            {
                object hh = dataGrid.Items[index];
                // may be virtualized, bring into view and try again
                dataGrid.ScrollIntoView(hh);
                dataGrid.UpdateLayout();
                row = (DataGridRow)dataGrid.ItemContainerGenerator.ContainerFromIndex(index);
            }
            return row;
        }
        public static T GetVisualChild<T>(Visual parent) where T : Visual
        {
            T child = default(T);
            int numVisuals = VisualTreeHelper.GetChildrenCount(parent);
            for (int i = 0; i < numVisuals; i++)
            {
                Visual v = (Visual)VisualTreeHelper.GetChild(parent, i);
                child = v as T;
                if (child == null)
                {
                    child = GetVisualChild<T>(v);
                }
                if (child != null)
                {
                    break;
                }
            }
            return child;
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need to hide a Windows form from the taskbar but I can't use
Im developing a touchscreen app and I need to hide the cursor whenever it
I am using Qt Dialogs in one of my application. I need to hide/delete
I need to find a way to hide HTML Rows (or Tables) from view
Need a way to allow sorting except for last item with in a list.
need ask you about some help. I have web app running in Net 2.0.
I am outputting a query but need to specify the first row of the
I have 4 Tables (listed bellow) and need: get last 10 Chats from Room
Last two nights I am struggle with below code. The problem is I need
I need some help to find a View inside a hierarchy. Here is how

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.