Class AddNewRecord
Defines and implements the class that adds a new record element 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.Grouping
Assembly: Syncfusion.Grouping.Base.dll
Syntax
public class AddNewRecord : Record, IDisposable, IDisposedEvent, IIsDisposedProperty, ITreeTableCounterSource, ITreeTableSummaryArraySource, IContainerElement, IElementTreeTableSource, IElement, IComparable, ICloneable
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 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, the changes 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 insert it into the group it belongs to. If no group is found where the record fits in, a new group will be created on the fly.
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 an 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 an 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 the AddNewRecord is a container element and not a display element, 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 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 record and keep track of its sorted display position within the 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 = table2.DisplayElements.IndexOf(r);
// Now, you can 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
AddNewRecord(AddNewRecordSection)
Initializes the new instances of the AddNewRecord class in the specified AddNewRecordSection.
Declaration
public AddNewRecord(AddNewRecordSection parent)
Parameters
Type | Name | Description |
---|---|---|
AddNewRecordSection | parent | The parent that this element belongs to. |
Properties
Kind
Gets the value of the display element kind.
Declaration
public override DisplayElementKind Kind { get; }
Property Value
Type |
---|
DisplayElementKind |
Overrides
UseDefaultValueInGetValue
Gets or sets the value of the AddNewRecord indicating whether it should retrieve the default value when its GetValue method is called.
Declaration
public bool UseDefaultValueInGetValue { get; set; }
Property Value
Type |
---|
System.Boolean |
Remarks
If UseDefaultValueInGetValue is false and also Engine.ShowDefaultValuesInAddNewRecord is false then the default values will only be assigned when AddNewRecord.BeginEdit is called. Prior calls to GetValue will return no value.
Methods
Dispose(Boolean)
Overrides and manages the unwanted resources.
Declaration
protected override void Dispose(bool disposing)
Parameters
Type | Name | Description |
---|---|---|
System.Boolean | disposing |
Overrides
GetData()
Overrides and returns the record data.
Declaration
public override object GetData()
Returns
Type | Description |
---|---|
System.Object | Record data. |
Overrides
GetElementCount()
Overrides and gets the number of elements.
Declaration
public override int GetElementCount()
Returns
Type | Description |
---|---|
System.Int32 | Element count. |
Overrides
GetFilteredRecordCount()
Overrides and gets the count of filtered records.
Declaration
public override int GetFilteredRecordCount()
Returns
Type | Description |
---|---|
System.Int32 | Number of filtered records. |
Overrides
GetRecordCount()
Overrides and gets the number of records.
Declaration
public override int GetRecordCount()
Returns
Type | Description |
---|---|
System.Int32 | Record count. |
Overrides
GetValue(FieldDescriptor)
Overrides and gets the value for the field specified.
Declaration
public override object GetValue(FieldDescriptor fieldDescriptor)
Parameters
Type | Name | Description |
---|---|---|
FieldDescriptor | fieldDescriptor | The descriptor of the field whose value is to be fetched. |
Returns
Type | Description |
---|---|
System.Object | Requested field value. |
Overrides
IsSelected()
Overrides and determines whether the record is selected or not.
Declaration
public override bool IsSelected()
Returns
Type | Description |
---|---|
System.Boolean | Returns false. |
Overrides
MeetsFilterCriteria()
Overrides and determines whether the record meets the filter criteria or not.
Declaration
public override bool MeetsFilterCriteria()
Returns
Type | Description |
---|---|
System.Boolean | Returns True. |
Overrides
OnBeginEditCalled()
Overrides and determines to support edit the added new record.
Declaration
public override bool OnBeginEditCalled()
Returns
Type | Description |
---|---|
System.Boolean | IfTrueediting new record can proceed;Otherwise False. |
Overrides
OnBeginEditComplete(Boolean)
Overrides and called when the BeginEdit() successfully finishes.
Declaration
public override void OnBeginEditComplete(bool success)
Parameters
Type | Name | Description |
---|---|---|
System.Boolean | success | IfTrueit is successfully finished;Otherwise False. |
Overrides
OnCancelEditComplete(Boolean)
Overrides and called when the CancelEdit() successfully finishes.
Declaration
public override void OnCancelEditComplete(bool success)
Parameters
Type | Name | Description |
---|---|---|
System.Boolean | success | IfTrueit is successfully finished;Otherwise False. |
Overrides
OnEndEditCalled()
Overrides and determines whether the EndEdit() method can be called or not.
Declaration
public override bool OnEndEditCalled()
Returns
Type | Description |
---|---|
System.Boolean | IfTrue then EndEdit() can proceed;Otherwise False. |
Overrides
OnEndEditComplete(Boolean)
Overrides and called when EndEdit() successfully finishes.
Declaration
public override void OnEndEditComplete(bool success)
Parameters
Type | Name | Description |
---|---|---|
System.Boolean | success | IfTrueit is successfully finished;Otherwise False. |
Overrides
OnEnterRecordCalled()
Overrides and determines if the source list allows adding new record.
Declaration
public override bool OnEnterRecordCalled()
Returns
Type | Description |
---|---|
System.Boolean | IfTrue new record is allowed; Otherwise False. |
Overrides
SetSelected(Boolean)
Overrides and sets the record as selected.
Declaration
public override void SetSelected(bool value)
Parameters
Type | Name | Description |
---|---|---|
System.Boolean | value | IfTruethe record should be marked as selected;Otherwise False. |
Overrides
SetValue(FieldDescriptor, Object)
Sets a value for the given field.
Declaration
public override void SetValue(FieldDescriptor fieldDescriptor, object value)
Parameters
Type | Name | Description |
---|---|---|
FieldDescriptor | fieldDescriptor | The field descriptor. |
System.Object | value | The Value. |
Overrides
Exceptions
Type | Condition |
---|---|
System.NotSupportedException | If the field consists of invalid field name. |
System.InvalidOperationException | Add new record is not performed. |