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

Want to make a single row editable

1 Answer 70 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Jason
Top achievements
Rank 1
Jason asked on 22 Aug 2011, 02:59 PM
Hello, I'm trying to create a grid that allows editing when I click a command column button but only for that row, all other rows should stay read-only to reduce human error.  Any ideas?

Thanks,
Jason

1 Answer, 1 is accepted

Sort by
0
Stefan
Telerik team
answered on 25 Aug 2011, 08:37 AM
Hi Jason,

Thank you for writing.

You can achieve the desired behavior by creating a flag which indicates whether edit is possible or not. The flag will be true when the button is clicked and false when the CurrentRow is changed. In order to allow or prevent the editing operation in the CellBeginEdit set the Cancel property from the arguments to the negate flag:
bool allowEdit = false;
 
void radGridView1_CellBeginEdit(object sender, GridViewCellCancelEventArgs e)
{
    e.Cancel = !allowEdit;
}
 
void radGridView1_CurrentRowChanged(object sender, CurrentRowChangedEventArgs e)
{
    allowEdit = false;
}
 
void radGridView1_CommandCellClick(object sender, EventArgs e)
{
    allowEdit = true;
}

I hope that you find this information helpful. Should you have any other questions, do not hesitate to contact us.
 
Regards,
Stefan
the Telerik team

Thank you for being the most amazing .NET community! Your unfailing support is what helps us charge forward! We'd appreciate your vote for Telerik in this year's DevProConnections Awards. We are competing in mind-blowing 20 categories and every vote counts! VOTE for Telerik NOW >>

Tags
GridView
Asked by
Jason
Top achievements
Rank 1
Answers by
Stefan
Telerik team
Share this question
or