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 BasicPublic 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();
}
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?
Hi,
I have extracted your inquiry to a separate Q461310 ticket. Please refer to it.