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

How to prevent empty rows creation?

3 Answers 169 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Oleksandr Vashchenko
Top achievements
Rank 1
Oleksandr Vashchenko asked on 22 Feb 2010, 05:53 PM

Hello.

When I enable rows creation in RadGridView and click that tells "Click here to add new row" new item is being added to binding source. But then if click somewhere (without entering any text to the cell) this empty row is being added to grid view. How can I change this behavior? I want that new row to be added only after entering some text or pressing "Enter" button.

Thanks.

3 Answers, 1 is accepted

Sort by
0
Martin Vasilev
Telerik team
answered on 25 Feb 2010, 07:37 AM
Hello Oleksandr Vashchenko,

Thank you for writing. You can use some of the validation capabilities in RadGridView to prevent confirming blank values. Please, take a look at our documentation how to validate data in RadGridView. Let me know if you have any additional questions.

Best wishes,
Martin Vasilev
the Telerik team

Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
0
Dan Harvey
Top achievements
Rank 2
answered on 12 Mar 2010, 09:14 PM
Hello, I have looked at the documentation and tried preventing an empty row being added by using the Row_validating event and it is just not working.  Please provide a code sample which implements this functionality.

Thanks,
0
Martin Vasilev
Telerik team
answered on 17 Mar 2010, 02:00 PM
Hello dan harvey,

Thank you for getting back to me.

Actually, I have discovered that we have some issues with the RowValidating event that prevent the grid to make a clean validation implementation when adding a new row (especially if it should not allow empty values). We will investigate this behavior further and will address it  in one of the next releases. Currently, you can use CellValidating instead:
 
void radGridView1_CellValidating(object sender, CellValidatingEventArgs e)
{
    if (e.Value != null && String.IsNullOrEmpty(e.Value.ToString()))
    {
        e.Cancel = true;
    }
}

Do not hesitate to contact me again if you have any other questions.

Greetings,
Martin Vasilev
the Telerik team

Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
Tags
GridView
Asked by
Oleksandr Vashchenko
Top achievements
Rank 1
Answers by
Martin Vasilev
Telerik team
Dan Harvey
Top achievements
Rank 2
Share this question
or