Posted 11 April 2023, 7:52 pm EST
- Updated 11 April 2023, 7:57 pm EST
Hi Daniel,
To add the rows programmatically, you could use the Insert() method available on the ObservableCollection that inserts an element at specified position.
You could create an object with default values and insert it to the ObservableCollection using the Insert method.
You could override the GetCellContentRenderFragment method, check for the “RowHeader” cell type and show the “*” character in the row header.
You could either show the “" character only on the first row when a new row is added or you could show the "” character on all the new rows added with default values.
Kindly refer to the following code snippet and the attached sample:
// Function to add New Row
private void AddNewRow()
{
// Create a new Object
dynamic weatherForecast = new ExpandoObject();
weatherForecast.Date = new DateTime();
weatherForecast.Summary = "Default Value";
weatherForecast.TemperatureC = 25;
// Insert the item
forecasts.Insert(0, weatherForecast);
newRowCount += 1;
isNewRowInserted = true;
}
private void ClearNewRowIndicator()
{
newRowCount = 0;
isNewRowInserted = false;
}
public override RenderFragment GetCellContentRenderFragment(GridCellType cellType, GridCellRange range)
{
// For single row to show indicator use
// (cellType == GridCellType.RowHeader && range.Row == 0 && isNewRowInserted)
if (cellType == GridCellType.RowHeader && range.Row < newRowCount)
{
// Render a Fragment with Empty String
RenderFragment rf3 = (builder) =>
{
builder.OpenElement(0, "div");
builder.AddAttribute(2, "class", "custom-class");
builder.AddContent(1, "*");
builder.CloseElement();
};
return rf3;
}
else
{
return base.GetCellContentRenderFragment(cellType, range);
}
}
Single Row to Show Indicator:

Multiple Rows to Show Indicator:

Regards,
Ankit
Sample: AddRowsToFlexGridProgamatically.zip