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

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

1 - works fine
2 - I will check this on Monday
3. - works fine

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


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