Class GridAddNewRecord
A record element for adding new records to the underlying data source. This element represents the empty record that is shown above the table records and / or below the records for each group and implements logic to add new records.
Implements
Inherited Members
Namespace: Syncfusion.Windows.Forms.Grid.Grouping
Assembly: Syncfusion.Grid.Grouping.Windows.dll
Syntax
public class GridAddNewRecord : AddNewRecord, IDisposable, IDisposedEvent, IIsDisposedProperty, ITreeTableCounterSource, ITreeTableSummaryArraySource, IContainerElement, IElementTreeTableSource, IElement, IComparable, ICloneable, IGridTableCellAppearanceSource, IGridTableCellStyleChanged
Remarks
This element represents the empty record that is shown above the table records and / or below the records for each group and implements logic to add new records.
The class is derived from a record. It adds special behavior such that the AddNewRecord is not bound to a record in the underlying table. Instead all fields are initially empty ( or default values based on parent group by criteria). When changes are made, they will be committed to the underlying table by adding a new record at the end of the underlying data source. The grouping engine will automatically insert the record into its sorted records collection and into the group it belongs to. If no group is found where the record fits in, a new group will be created.
AddNewRecord(s) can be optionally displayed at the start of table below the column headers and / or at the end of each group.
AddNewRecord belongs to a AddNewRecordSection and is its only element.
If AddNewRecord(s) should be displayed at end of each group (see also Engine.ShowAddNewRecordInGroups) then AddNewRecordSection(s) are created when the grouping for a table is initialized. The grouping engine loops through all sorted records and categorizes them. For each new group the virtual TableDescriptor.CreateGroup factory method is called. The TableDescriptor.CreateGroup method instantiates a AddNewRecordSection by calling the virtual TableDescriptor.CreateAddNewRecordSection factory method.
One AddNewRecord is displayed at the top of the table below the column headers. It belongs to the AddNewRecordSection of the TopLevelGroup of a table. The TopLevelGroup is created with the virtual TableDescriptor.CreateGroup factory method. The TableDescriptor.CreateGroup method instantiates an AddNewRecordSection by calling the virtual TableDescriptor.CreateAddNewRecordSection factory method.
AddNewRecord is a container element. It contains one or multiple RecordParts.
Because AddNewRecord is a container element and not a display element and it will not be an item returned by the Table.DisplayElements and Table.GroupedElements collection. Instead, AddNewRecord is only returned by the RecordsDetails.Records collection of its parent AddNewRecordSection (or the Group.Records collection of its ParentGroup which is a shortcut instead of accessing it through AddNewRecordSection).
See also the Engine.RecordAsDisplayElements on how to make AddNewRecord be treated as a display element if you have no need for nested elements within a record., e.g. if you only want to display a single table and you do not need multiple row elements per record and / or nested tables. (However, do not change this setting if you intend to use the engine as grid data model.)
The first record part is a RecordRowsPart. A RecordRowsPart contains one or multiple RecordRows displayed in a grid for the record.
The second record part represents nested tables. If relations have been defined for the table (see TableDescriptor.Relations) and the current table has a foreign key relationship setup to other tables, a table is added to the RecordPart[1].NestedTables collection for each relation. You can access nested tables in a record with the Record.NestedTables collection.
AddNewRecord can be set as the current record in a table if you want to edit its data through the engine.
The first time a value is changed by the grid, Record.BeginEdit is called before the value is assigned. When the user moves the current cell in the grid to a new record, the changes are committed with a Record.EndEdit call. If the user presses Escape, the changes are rolled back with a Record.CancelEdit call. If the user presses Enter, the changes are committed and the record's new display position is determined and the current cell is moved to the new display position of the record. If validation fails during EndEdit, the grid will try to identify the column which violated the record constraints and display a red error indicator for that column with a ToolTip text showing the exception text when the user hovers the mouse over the red arrow indicator.
See the CurrentRecordManager class for a description of events raised when modifying columns in the AddNewRecord row or when BeginEdit, CancelEdit, or EndEdit was called.
See also: CurrentRecordManager, CurrentRecordManager.IsAddNewRecord, CurrentRecordManager.NavigateTo, Group.AddNewRecord, Table.AddNewRecord, TableDescriptor.CreateGroup, Table.TopLevelGroup, AddNewRecordSection, IContainerElement, RecordsDetails.Records, Group.Records
Examples
The following example shows how you can add records and keep track of sorted display positions within a table:
// Add a record to Table table2
Record r = table2.AddNewRecord;
r.SetCurrent(); // Makes it the current record, saving any pending changes previous current record.
if (r.IsCurrent)
{
r.BeginEdit();
if (r.IsEditing)
{
r.SetValue("Country", "USA");
r.SetValue("Region", "NC");
r.SetValue("CustomerID", "SYNC
r.SetValue("CompanyName", "Syncfusion");
r.EndEdit();
}
}
int displayPos = table.DisplayElements.IndexOf(r);
// Now, you could navigate the current cell of a grid to row displayPos and highlight the newly added row
// within its correct group category and sort order
Constructors
GridAddNewRecord(AddNewRecordSection)
Initializes the new instance of the GridAddNewRecord class.
Declaration
public GridAddNewRecord(AddNewRecordSection parent)
Parameters
Type | Name | Description |
---|---|---|
AddNewRecordSection | parent | The parent that this element belongs to. |
Properties
Appearance
Gets or sets the default GridTableCellAppearance with GridTableCellStyleInfo information for cells of this element.
Declaration
public GridTableCellAppearance Appearance { get; set; }
Property Value
Type |
---|
GridTableCellAppearance |
Engine
Gets the engine this element belongs to.
Declaration
public GridEngine Engine { get; }
Property Value
Type |
---|
GridEngine |
EngineTable
Declaration
public GridTable EngineTable { get; }
Property Value
Type |
---|
GridTable |
IsCollapsible
Gets the current element is collapsible.
Declaration
public override bool IsCollapsible { get; }
Property Value
Type |
---|
System.Boolean |
Overrides
ParentChildTable
Gets a reference to the child table this element belongs.
Declaration
public GridChildTable ParentChildTable { get; }
Property Value
Type |
---|
GridChildTable |
ParentRecord
Gets a reference to the parent record this element belongs to.
Declaration
public GridRecord ParentRecord { get; }
Property Value
Type |
---|
GridRecord |
ParentTable
Gets a reference to the parent table this element belongs to.
Declaration
public GridTable ParentTable { get; set; }
Property Value
Type |
---|
GridTable |
ParentTableDescriptor
Gets the table descriptor this element belongs to.
Declaration
public GridTableDescriptor ParentTableDescriptor { get; }
Property Value
Type |
---|
GridTableDescriptor |
ReadOnlyAppearance
If this element is modified, the Appearance returns this object's Appearance; otherwise it returns a GridTableCellAppearance of the first parent element with appearance in the hierarchy.
Declaration
public GridTableCellAppearance ReadOnlyAppearance { get; }
Property Value
Type |
---|
GridTableCellAppearance |
Methods
Dispose(Boolean)
Declaration
protected override void Dispose(bool disposing)
Parameters
Type | Name | Description |
---|---|---|
System.Boolean | disposing |
Overrides
GetBaseAppearance()
Returns a GridTableCellAppearance of the first parent element with appearance in the hierarchy.
Declaration
public GridTableCellAppearance GetBaseAppearance()
Returns
Type | Description |
---|---|
GridTableCellAppearance |
ResetAppearance()
Discards any changes for the Appearance object.
Declaration
public void ResetAppearance()
ShouldSerializeAppearance()
Determines whether Appearance has been modified and contents should be serialized at design-time.
Declaration
public bool ShouldSerializeAppearance()
Returns
Type | Description |
---|---|
System.Boolean | True if contents were changed; False otherwise. |
ShouldShowRecordPreviewRows()
Indicates whether to show the record preview rows.
Declaration
public override bool ShouldShowRecordPreviewRows()
Returns
Type | Description |
---|---|
System.Boolean | returns the boolean value False. |
Overrides
Explicit Interface Implementations
IGridTableCellAppearanceSource.GetAppearance()
Declaration
GridTableCellAppearance IGridTableCellAppearanceSource.GetAppearance()
Returns
Type |
---|
GridTableCellAppearance |
IGridTableCellAppearanceSource.RaiseAppearanceChanged(GridTableCellStyleInfoChangedEventArgs)
Declaration
void IGridTableCellAppearanceSource.RaiseAppearanceChanged(GridTableCellStyleInfoChangedEventArgs e)
Parameters
Type | Name | Description |
---|---|---|
GridTableCellStyleInfoChangedEventArgs | e |
IGridTableCellAppearanceSource.RaiseAppearanceChanging(GridTableCellStyleInfoChangedEventArgs)
Declaration
void IGridTableCellAppearanceSource.RaiseAppearanceChanging(GridTableCellStyleInfoChangedEventArgs e)
Parameters
Type | Name | Description |
---|---|---|
GridTableCellStyleInfoChangedEventArgs | e |
IGridTableCellStyleChanged.RaiseTableCellStyleChanged(GridTableCellStyleInfoEventArgs)
Declaration
void IGridTableCellStyleChanged.RaiseTableCellStyleChanged(GridTableCellStyleInfoEventArgs e)
Parameters
Type | Name | Description |
---|---|---|
GridTableCellStyleInfoEventArgs | e |