KB Article A1043
Visible to All Users

How to insert a new data row into the current group in a grouped XtraGrid

Description:
I wish to add new rows to a grouped grid, but the New Item Row is not displayed in this case. How can I do this?

Answer:
You can add a button onto a toolbar for adding new rows. The button's Click event handler should call the procedure listed below. Please pay attention to the code, which initializes the new row's columns with the values of the current groups. It is necessary to make the new row appear in the desired group.

Visual Basic
Public Sub AddRow(ByVal View As DevExpress.XtraGrid.Views.Grid.GridView) Dim currentRow As Integer currentRow = View.FocusedRowHandle If currentRow < 0 Then currentRow = View.GetDataRowHandleByGroupRowHandle(currentRow) End If View.AddNewRow() If View.GroupedColumns.Count = 0 Then Exit Sub ' Initialize group values Dim groupColumn As DevExpress.XtraGrid.Columns.GridColumn For Each groupColumn In View.GroupedColumns Dim value As Object = View.GetRowCellValue(currentRow, groupColumn) View.SetRowCellValue(View.FocusedRowHandle, groupColumn, value) Next View.UpdateCurrentRow() View.MakeRowVisible(View.FocusedRowHandle, True) View.ShowEditor() End Sub
C#
public void AddRow(DevExpress.XtraGrid.Views.Grid.GridView View) { int currentRow; currentRow = View.FocusedRowHandle; if (currentRow < 0) { currentRow = View.GetDataRowHandleByGroupRowHandle(currentRow); } View.AddNewRow(); if (View.GroupedColumns.Count == 0) return; // Initialize group values foreach (GridColumn groupColumn in View.GroupedColumns) { object value = View.GetRowCellValue(currentRow, groupColumn); View.SetRowCellValue(View.FocusedRowHandle, groupColumn, value); } View.UpdateCurrentRow(); View.MakeRowVisible(View.FocusedRowHandle, true); View.ShowEditor(); }
Comments (2)
YA YA
Youssef Azarouali 2 11 years ago

    Can you explain how to do it exactly? Where does the newrow appear? Or doe you have to build your own form with information for the row on it?

    DevExpress Support Team 11 years ago

      Hi,
      I have extracted your inquiry to a separate Q461310 ticket. Please refer to it.

      Disclaimer: The information provided on DevExpress.com and affiliated web properties (including the DevExpress Support Center) is provided "as is" without warranty of any kind. Developer Express Inc disclaims all warranties, either express or implied, including the warranties of merchantability and fitness for a particular purpose. Please refer to the DevExpress.com Website Terms of Use for more information in this regard.

      Confidential Information: Developer Express Inc does not wish to receive, will not act to procure, nor will it solicit, confidential or proprietary materials and information from you through the DevExpress Support Center or its web properties. Any and all materials or information divulged during chats, email communications, online discussions, Support Center tickets, or made available to Developer Express Inc in any manner will be deemed NOT to be confidential by Developer Express Inc. Please refer to the DevExpress.com Website Terms of Use for more information in this regard.