Why isDefaultValuesNeeded not fired when programmatically adding a row to a gridview?
1 Answer, 1 is accepted
0
Nadya | Tech Support Engineer
Telerik team
answered on 07 Oct 2025, 12:24 PM
Hello, Rob,
The DefaultValuesNeeded event is not fired when programmatically adding rows to a RadGridView because this event is specifically designed for user-initiated row additions through the grid's UI interface. DefaultValuesNeeded event triggers only when users interact with the grid's "New Row" feature, and this is by design. The most common use case is when you have an empty field where the user can enter their own values, but you also want to display default suggestions that may assist the user.
For programmatic additions, you need to handle default values manually in your code. I prepared an example for you where a new GridViewDataRowInfo is added to RadGridView.Rows collection on a button_Click. Then, default values are assigned to each cell using RowsChanged event.
privatevoidradButton1_Click(object sender, EventArgs e)
{
//Add new GridViewDataRowInfothis.radGridView2.Rows.AddNew();
}
privatevoidRadGridView2_RowsChanged(object sender, GridViewCollectionChangedEventArgs e)
{
if (e.Action == Telerik.WinControls.Data.NotifyCollectionChangedAction.Add)
{
GridViewDataRowInfo newrow = e.NewItems[0] as GridViewDataRowInfo;
if (newrow != null)
{
//assign values for each cell
newrow.Cells["Make"].Value = "New Make";
newrow.Cells["Model"].Value = "New Model";
newrow.Cells["Year"].Value = DateTime.Now.Year;
newrow.Cells["Price"].Value = 30000m;
}
}
}
You can use a similar approach to assign pre-defined values to your grid when adding a new row programmatically, either directly to the grid or to the binding collection.
I hope this information helps. If you have other questions, please let me know.
Regards,
Nadya | Tech Support Engineer
Progress Telerik
Your perspective matters! Join other professionals in the State of Designer-Developer Collaboration 2025: Workflows, Trends and AI survey to share how AI and new workflows are impacting collaboration, and be among the first to see the key findings. Start the 2025 Survey