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

Three problems with adding new row.

6 Answers 311 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Raymond
Top achievements
Rank 1
Raymond asked on 15 Oct 2010, 12:37 PM

Hi
Version: 2010 Q2 SP2

1. When grid has at least one real row in row for adding new rows there is text:
    “Click here to add new row”.
    Problem is when grid is empty and there is only row for adding new rows.
    Then this row is selected and there is no text “Click here to add new row”.
    It might be confusing to the user – user might not know how to add new row.

    How can I display text “Click here to add new row” in row for adding new rows if grid is empty (there are no real rows)?

2. If during adding new row user presses Esc button adding is canceled and text “Click here to add new row” is displaying – this is ok.
    How can I know that user canceled adding new row? Is there any event for this?

3. Can I use some another text than “Click here to add new row”? 
    I would like to define my own text for adding new rows.

Regards.

6 Answers, 1 is accepted

Sort by
0
Accepted
Emanuel Varga
Top achievements
Rank 1
answered on 15 Oct 2010, 02:14 PM
Hello Raymond,

1. Because you are on that row, that text has to hide otherwise it will create some visual glitches, but you can try it for yourself like so: Register for the ViewRowFormatting event and if the row element is GridNewRowElement you can take the new new string from the localization (in the final step you will see how to create custom localization strings for the grid)
void radGridView1_ViewRowFormatting(object sender, RowFormattingEventArgs e)
{
    if (e.RowElement is GridNewRowElement)
    {
        e.RowElement.Text = RadGridLocalizationProvider.CurrentProvider.GetLocalizedString(RadGridStringId.AddNewRowString);
    }
}

2. Not that i am aware of, here you will find the sequence of events fired during and edit operation

3. In order to change this you will have to create a custom localization provider for the grid, there is an article on how to do this here, and a list of all the latest strings here.

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

Best Regards,
Emanuel Varga
0
Raymond
Top achievements
Rank 1
answered on 15 Oct 2010, 02:58 PM
thanks for help

1 - works fine
2 - I will check this on Monday
3. - works fine
0
Emanuel Varga
Top achievements
Rank 1
answered on 15 Oct 2010, 03:06 PM
Glad to hear it, if you need any more help please do not hesitate to say so,

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

Best Regards,
Emanuel Varga
0
Raymond
Top achievements
Rank 1
answered on 18 Oct 2010, 10:39 AM
everything is fine, thanks
0
Emanuel Varga
Top achievements
Rank 1
answered on 18 Oct 2010, 12:37 PM
Sorry, wrong thread :(
0
Accepted
Jack
Telerik team
answered on 21 Oct 2010, 12:14 PM
Hi Raymond,

Regarding your questions:

1. Yes, this is a limitation in the current version of RadGridView. I was able to work around the issue partially. You should set the AllowAddNewRow property to false before setting the DataSource. Here is a sample:
this.radGridView1.MasterTemplate.AllowAddNewRow = false;
BindDataTable();
this.radGridView1.MasterTemplate.AllowAddNewRow = true;

However, this solution will work only the first time, until you click in the row. I added this as a feature request and we will consider changing our behavior in the upcoming Q3 release.

2. There is no event when canceling the process of adding a new row because in this case nothing changes in RadGridView. However, you can handle this case by overriding the default grid behavior. Here is a sample:
this.radGridView1.GridBehavior = new CustomGridBehavior();
public class CustomGridBehavior : BaseGridBehavior
{
    public override bool ProcessKey(KeyEventArgs keys)
    {
        if (keys.KeyCode == Keys.Escape && GridControl.CurrentRow is GridViewNewRowInfo)
        {
            // do something ...
        }
        return base.ProcessKey(keys);
    }
}

3. Please check the solution provided by Emanuel. I think that it will fit into your scenario.

If you have any further questions, I will be glad to help.

Regards,
Jack
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
Raymond
Top achievements
Rank 1
Answers by
Emanuel Varga
Top achievements
Rank 1
Raymond
Top achievements
Rank 1
Jack
Telerik team
Share this question
or