This is a migrated thread and some comments may be shown as answers.

RadGridView1.Rows.AddNew not assigning default values

2 Answers 103 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Bijimon
Top achievements
Rank 1
Bijimon asked on 05 Apr 2011, 03:03 PM
I am using an unbound grid. Adding columns and rows programmatically to the grid in a sub procedure I am calling InitializeGrid. At the end of this initialize procedure I have the following code

 

 

AddHandler RadGridView1.DefaultValuesNeeded, AddressOf radGridView1_DefaultValuesNeeded

 

This works fine when the user clicks on "Click here to add a new row" message. It assigns the default values as specified in the radGridView1_DefaultValuesNeeded sub. But it doesn't work when I do that programmatically by calling the RadGridView1.Rows.AddNew method.  How can I programmatically mimic the user clicking on "Click here to add a new row"?

Thank you

2 Answers, 1 is accepted

Sort by
0
Accepted
Emanuel Varga
Top achievements
Rank 1
answered on 05 Apr 2011, 08:47 PM
Hello Bishop,

I don't know if i really understood what you are trying to achieve here, but something like this should work for you:
protected override void OnLoad(EventArgs e)
{
    base.OnLoad(e);
 
    var row = radGridView1.Rows.AddNew();
    GetDefaultValuesForRow(row);
}
 
void radGridView1_DefaultValuesNeeded(object sender, GridViewRowEventArgs e)
{
    GetDefaultValuesForRow(e.Row);
    
}
 
private void GetDefaultValuesForRow(GridViewRowInfo rowInfo)
{
    rowInfo.Cells[0].Value = 100;
}

Hope this helps, if you have any other questions or comments, please let me know,

Best Regards,
Emanuel Varga

Telerik WinForms MVP
0
Bijimon
Top achievements
Rank 1
answered on 06 Apr 2011, 12:04 AM
Worked like a charm.
Thank you!
Tags
GridView
Asked by
Bijimon
Top achievements
Rank 1
Answers by
Emanuel Varga
Top achievements
Rank 1
Bijimon
Top achievements
Rank 1
Share this question
or