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

How to hide "click here to add new row" option on radGridView

31 Answers 873 Views
GridView
This is a migrated thread and some comments may be shown as answers.
raj
Top achievements
Rank 1
raj asked on 14 Dec 2007, 09:02 PM
I would like to hide "click here to add new row" option on radGridView.

Thanks,
Rajesh
Kapil
Top achievements
Rank 1
Iron
commented on 10 May 2021, 06:47 PM

i m trying to show ""click here to add new row" in winform but it's not appearing

i tried this


radGridView1.MasterGridViewTemplate.AllowAddNewRow = true;
And
radGridView1.AllowAddNewRow = true;;
but nothing seems to work
Dess | Tech Support Engineer, Principal
Telerik team
commented on 11 May 2021, 05:27 AM

Hello, Kapil,

Setting the AllowAddNewRow property to true enables the new row. However, please have in mind that the "Click here to add a new row" text is shown only when the new row is NOT current:

Once the new row is selected, the text is hidden and you are expected to see the respective cells. The RadGridView.CurrentRow property controls which row is currently focused. You can set it either to null or to any of the data rows stored in the RadGridView.Rows collection. Thus, the new row text will be shown.

I hope this information helps. If you need any further assistance please don't hesitate to contact me. 

 

31 Answers, 1 is accepted

Sort by
0
Accepted
Nikolay
Telerik team
answered on 15 Dec 2007, 12:32 PM
Hello raj,

Thank you for writing.

You can hide "Click here to add new row" by using the designer or programmatically.
 
If you want to use the designer, select RadGridView and in the Properties panel, navigate to the MasterGridViewTemplate property, then click the "+" sign to open a list of its subproperties and set the AllowAddNewRow property to false.

To do this programmatically, paste the following code snippet into the Form_Load event handler:
radGridView1.MasterGridViewTemplate.AllowAddNewRow = false

If you have further questions, do not hesitate to contact us.

Greetings,
Nikolay
the Telerik team

Instantly find answers to your questions at the new Telerik Support Center
0
Clint Tennill
Top achievements
Rank 1
answered on 19 Dec 2007, 05:43 PM
Got it.
0
Sofia
Top achievements
Rank 1
answered on 03 May 2008, 08:40 AM
Hi,

Is there a way to "allow add new row" but not display the text "Click here to add new row" ?
0
Dwight
Telerik team
answered on 05 May 2008, 08:34 AM
Hi Sofia,

Thank you for bringing this question to our attention. You can set the text in this row to string.Empty by creating and using your own localization provider. Here is the sample code:

public partial class Form1 : Form 
    public Form1() 
    { 
        InitializeComponent(); 
        RadGridLocalizationProvider.CurrentProvider = new CustomLocalizationProvider(); 
    } 
 
public class CustomLocalizationProvider : RadGridLocalizationProvider 
    public override string GetLocalizedString(string id) 
    { 
        switch (id) 
        { 
            case RadGridStringId.AddNewRowString: return string.Empty; 
        } 
 
        return base.GetLocalizedString(id); 
    } 

Please, keep in mind that this localization provider is static and will be used from that point on for all instances of RadGridView. If you'd like to go back to the original one, you need to set it back at an appropriate time in the execution of the application.

Consult the Localization example of the RadGridView in our examples application. In the code, you'll notice that the default localization provider is restored when the form is closed.

If you have any additional questions, please let me know.

Regards,
Evtim
the Telerik team

Instantly find answers to your questions at the new Telerik Support Center
0
Ryan
Top achievements
Rank 1
answered on 11 Aug 2008, 02:32 AM
Would you mind posting the VB equivalent for the CustomLocalizationProvider?
0
Martin Vasilev
Telerik team
answered on 11 Aug 2008, 12:40 PM
Hi Ryan,

Thank you for contacting me.

Here you are the same code in VB.Net:
Public Partial Class Form1 
    Inherits Form 
    Public Sub New() 
        InitializeComponent() 
        RadGridLocalizationProvider.CurrentProvider = New CustomLocalizationProvider() 
    End Sub 
End Class 
 
Public Class CustomLocalizationProvider 
    Inherits RadGridLocalizationProvider 
    Public Overloads Overrides Function GetLocalizedString(ByVal id As StringAs String 
        Select Case id 
            Case RadGridStringId.AddNewRowString 
                Return String.Empty 
        End Select 
 
        Return MyBase.GetLocalizedString(id) 
    End Function 
End Class 

You could find and use C#/VB.Net converter in all similar cases here:
http://codechanger.com/default.aspx

If you have other questions, do not hesitate to contact me again.

Greetings,
Martin Vasilev
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
0
Alcatraz
Top achievements
Rank 1
answered on 14 Jun 2010, 10:27 AM
Hi,

Is it possible to Align the "Click here to add new row" text to left or right?  If yes, could you please let me know the steps.

Thanks
Krishnan N
0
Martin Vasilev
Telerik team
answered on 16 Jun 2010, 12:43 PM
Hi Krishnan,

Thank you for writing.

You can change the text alignment of the new row in ViewCellFormatting event. Please consider the following code snippet:
void radGridView1_ViewCellFormatting(object sender, CellFormattingEventArgs e)
{
    if (e.CellElement.RowElement is GridNewRowElement)
    {
        e.CellElement.RowElement.TextAlignment = ContentAlignment.MiddleLeft;
        if (e.CellElement is GridRowHeaderCellElement)
        {
            if (this.radGridView1.IsInEditMode)
            {
                e.CellElement.Visibility = ElementVisibility.Visible;
            }
            else
            {
                e.CellElement.Visibility = ElementVisibility.Hidden;
            }
        }
    }
}

I hope this helps. Let me know if you have any other questions.

Regards,
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
Sheraz Naseeb
Top achievements
Rank 1
answered on 13 Aug 2010, 12:28 PM
Hi There,
 
Is there any possible way to change "Click here to add new row" text to our customised text I tried the following but didnt work...

e.CellElement.RowElement.Text = "Click here to add new order extras..."

Many thanks,
0
Martin Vasilev
Telerik team
answered on 17 Aug 2010, 05:16 PM
Hi Sheraz Naseeb,

Thanks for writing.

You can change the default text of new row element in the RowFormatting event:

void radGridView1_ViewRowFormatting(object sender, RowFormattingEventArgs e)
{
    if (e.RowElement is GridNewRowElement)
    {
        e.RowElement.Text = "My custom add new row text";
    }
}

I hope this helps. Let me know 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
0
Sheraz Naseeb
Top achievements
Rank 1
answered on 16 Sep 2010, 12:30 PM
Hi Telerik Team,

This GridNewRowElement does not work in ViewRowFormatting event and it says "'GridNewRowElement' is a type and cannot be used as experession". I even tried to cast it as RowElement but not working. My code is as following.

If e.RowElement Is DirectCast(e.RowElement, GridNewRowElement) Then
    e.RowElement.Text = "MyText"
End If

And I would like to do the same thing with my "Drag a column here to group by this column." I would like to add custom text here or may be just remove that text but still enable grouping.

Please help,

Many thanks,

Sheraz
0
Vinh
Top achievements
Rank 1
answered on 17 Sep 2010, 10:15 PM
How do it do it for the new RadGridView for silverlight. I couldn't find a way to hide it. Thx.
0
Martin Vasilev
Telerik team
answered on 20 Sep 2010, 04:42 PM
Hi guys,

Vinh, this topic covers only RadGridView for WinForms. Please open a new thread in our Silverlight section with your questions in order to get appropriate response.

Sheraz, please try the following code in VB:
 
Private Sub radGridView1_ViewRowFormatting(sender As Object, e As RowFormattingEventArgs)
    If TypeOf e.RowElement Is GridNewRowElement Then
        e.RowElement.Text = "My custom add new row text"
    End If
End Sub

Let me know if it still does not do the job.


Sincerely yours,
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
Vinh
Top achievements
Rank 1
answered on 20 Sep 2010, 04:53 PM
There's no such method as ViewRowFormatting for RadGridView (Silverlight). I will open a new thread. Thanks.
0
Sheraz Naseeb
Top achievements
Rank 1
answered on 20 Sep 2010, 05:14 PM
Hi Martin,

Its still not working, can you please help me quick on this issue I am trying to sort it out for about a month but no luck so far.

And also for Grouping row I would like it to show nothing as text but want the grouping enabled.

Thanks,

Sheraz
0
Martin Vasilev
Telerik team
answered on 22 Sep 2010, 01:26 PM
Hi Sheraz Naseeb,

Please find a small sample VB.Net project, which demonstrates how to customize the add new row and group panel texts, as an attachment to this message. Let me know if you still have any additional questions.

Sincerely yours,
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
Sheraz Naseeb
Top achievements
Rank 1
answered on 22 Sep 2010, 02:16 PM
Hello Martin,

Thats very kind of you sending me the sample project, but unfortunately I have to say that its not working on my end. I have attached a jpg image for your reference.

First of all the version I am using is Q1 2009, and I guess in this version we dont have "RadGridView1.GridViewElement.GroupPanelElement.Text" property so I have to comment that.

It will be explained more when you see the image.

Thanks,

Sheraz
0
Martin Vasilev
Telerik team
answered on 24 Sep 2010, 01:54 PM
Hello Sheraz Naseeb,

Thank you for contacting me again.

Now I understand that you are using an old version of RadControls and that is the reason why my project do not work on your side. I highly recommend upgrading to the latest version Q2 2010 SP2, which contains a lot of improvements and fixes. It also would allow you to change the add new row and group panel text according to your needs.

Regards,
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
Ifdev02
Top achievements
Rank 1
answered on 12 Oct 2010, 09:50 AM
I am using the code in example but it only change text when user is in edit mode on the row "Click here to add a new row"
The rest of the time the text wont change.

void radGridView1_ViewRowFormatting(object sender, RowFormattingEventArgs e)
{
    if (e.RowElement is GridNewRowElement)
    {
        e.RowElement.Text = "My custom add new row text";
    }
}
0
Emanuel Varga
Top achievements
Rank 1
answered on 12 Oct 2010, 10:44 AM
Hello,

I would suggest to use a custom RadGridLocalizationProvider to achieve this, it's the cleanest approach and also the easiest to maintain, plus you can use the same provider for multiple grids.

You can find a sample on somewhere on top of this page, but also, following up is a sample adapted to your question:
RadGridLocalizationProvider.CurrentProvider = new CustomLocalizationProvider();
 
public class CustomLocalizationProvider : RadGridLocalizationProvider
{
    public override string GetLocalizedString(string id)
    {
        switch (id)
        {
            case RadGridStringId.AddNewRowString:
                return "My custom add new row text";
        }
 
        return base.GetLocalizedString(id);
    }
}

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

Best Regards,
Emanuel Varga
0
Brian Manning
Top achievements
Rank 1
answered on 20 Oct 2010, 04:25 PM
The localization angle looks interesting, but I don't think it'll work for my scenario.  I have a grid with 3 different hierarchy levels and we'd like the text to be different at each level.

It'd be great if the e.RowElement.Text trick worked, but I'm using the latest tools (2010.2.10.914) and I can confirm that it only displays my custom text after a user has clicked in the row.  Is there a different property that I'm missing?
0
Brian Manning
Top achievements
Rank 1
answered on 20 Oct 2010, 05:52 PM
Sorry to double post, but I found a workaround:

First you need to implement a custom GridNewRowElement:

public class CustomGridNewRowElement : GridNewRowElement
{
    //Prevent themes from getting all messed up
    protected override Type ThemeEffectiveType
    {
        get
        {
            return typeof(GridNewRowElement);
        }
    }
  
    public override void UpdateContentVisibility(bool showCells)
    {
        base.UpdateContentVisibility(showCells);
  
        if (this.Text != string.Empty)
        {
            if (this.RowInfo.HierarchyLevel == 0)
            {
                this.Text = "Click here to add a new Level 0 Thing";
            }
            else if (this.RowInfo.HierarchyLevel == 1)
            {
                this.Text = "Click here to add a new Level 1 Thing";
            }
            else if (this.RowInfo.HierarchyLevel == 2)
            {
                this.Text = "Click here to add a new Level 2 Thing";
            }
        }
    }
}

Next you do the following either in the OnCreateRow call of a custom grid class or in the CreateRow event handler:

if (e.RowType == typeof(GridNewRowElement))
  e.RowType = typeof(CustomGridNewRowElement);
 
//only do this if you're using a custom GridView class
base.OnCreateRow(sender, e);
0
Emanuel Varga
Top achievements
Rank 1
answered on 20 Oct 2010, 06:10 PM
Hello, @Brian: Thank you for sharing your sollution with the community. I have to add something i I may, I had some bad experiences when using the CreateRow event, because of grid virtualization because the grid reuses cells, it might cause some anomalies. If you notice any kind of problems I suggest you implement and use a custom cell provider also. Honestly I prefer overriding the localization, easier to keep consistency troughout the software. Best Regards, Emanuel Varga
0
Brian Manning
Top achievements
Rank 1
answered on 20 Oct 2010, 07:30 PM
Thanks for the heads up.  I'll keep my eyes open, but I haven't seen anything suspicious yet.  It seems like that UpdateContentVisibility method gets called whenever the row gets formatted, so I'm hoping it won't be an issue.
0
simon
Top achievements
Rank 1
answered on 07 Jan 2015, 11:00 AM
Hi,

It seems if I use the RadGridView, 
the option "click here to add new row" is only visible after I edited the first row.
If i use 'tab' to navigate through the cells i eventually enter a new second row.
But at that moment the option "click here to add new row" is not available anymore.
Is it possible to make that option ALWAYS available and make it not dissapear when i enter a new row by 'tabbing'

thanks,
simon


0
Hristo
Telerik team
answered on 08 Jan 2015, 05:43 PM
Hi Simon,

Thank you for writing.

As already mentioned in some of the posts above, the availability of a GridNewRowElement is controlled by the value of the AllowAddNewRow property of the grid and by default it is set to true.

Indeed, it is possible to reach a behavior where the text of the GridNewRowElement is missing. This might happen in a grid in which the columns are present but there are no data rows. In this case the first row becomes CurrentRow and the cells responsible for user input become visible. You can set the CurrentRow property to null and this way the text of the GridNewRowElement would be visible right after the form has been loaded.

If this in not your exact case please provide me with some additional information so that I can reproduce it and provide you with a solution.

Regards,
Hristo
Telerik
 

Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

 
0
Jashwanth
Top achievements
Rank 1
answered on 21 Apr 2015, 09:22 AM
Is there any way to have Add New Row option at the bottom of the Grid rather having at the top?
0
Dess | Tech Support Engineer, Principal
Telerik team
answered on 21 Apr 2015, 12:04 PM
Hello Jashwanth,

Thank you for writing.

You can achieve it by setting the RadGridView.AddNewRowPosition property to SystemRowPosition.Bottom.

I hope this information helps. Should you have further questions, I would be glad to help.
 
Regards,
Dess
Telerik
 

See What's Next in App Development. Register for TelerikNEXT.

 
0
Terje
Top achievements
Rank 2
answered on 13 May 2016, 01:55 PM

Hi!

I'n my rgv I've set AllowAddNewRow  = true, but still I'm not able to cange the "add new row"-line.

e.RowElement is never GridNewRowElement. Any sugestions? I just want to change the colors, not realy the text.

        private void rgv_RowFormatting(object sender, RowFormattingEventArgs e)
        {
            if (e.RowElement is GridNewRowElement)
            {
                e.RowElement.Text = "My custom add new row text";
                e.RowElement.DrawFill = true;
                e.RowElement.BackColor = Color.Navy;
                e.RowElement.NumberOfColors = 1;
            }
        }

0
Hristo
Telerik team
answered on 13 May 2016, 03:28 PM
Hello Terje,

Thank you for writing.

Please make sure that you subscribe to the ViewRowFormatting event since the RowFormatting event fires only for the data rows: Row Formatting. Please check my code snippet below: 
public partial class Form1 : Form
{
    public Form1()
    {
        InitializeComponent();
 
        this.radGridView1.DataSource = this.GetData();
       
        this.radGridView1.ViewRowFormatting += radGridView1_ViewRowFormatting;
    }
 
    private void radGridView1_ViewRowFormatting(object sender, RowFormattingEventArgs e)
    {
        if (e.RowElement is GridNewRowElement)
        {
            e.RowElement.Text = "My custom add new row text";
            e.RowElement.DrawFill = true;
            e.RowElement.BackColor = Color.Navy;
            e.RowElement.NumberOfColors = 1;
        }
    }
}

I hope this helps. Should you have further questions please do not hesitate to write back.

Regards,
Hristo Merdjanov
Telerik
Do you need help with upgrading your AJAX, WPF or WinForms project? Check the Telerik API Analyzer and share your thoughts.
0
Terje
Top achievements
Rank 2
answered on 16 May 2016, 08:58 PM

Hi!

 

Thank's for fast answer Hristo Merdjanov, I got it working now.

I also see that every post before me was talking about ViewRowFormatting, and not RowFormatting, which I was using..

Tags
GridView
Asked by
raj
Top achievements
Rank 1
Answers by
Nikolay
Telerik team
Clint Tennill
Top achievements
Rank 1
Sofia
Top achievements
Rank 1
Dwight
Telerik team
Ryan
Top achievements
Rank 1
Martin Vasilev
Telerik team
Alcatraz
Top achievements
Rank 1
Sheraz Naseeb
Top achievements
Rank 1
Vinh
Top achievements
Rank 1
Ifdev02
Top achievements
Rank 1
Emanuel Varga
Top achievements
Rank 1
Brian Manning
Top achievements
Rank 1
simon
Top achievements
Rank 1
Hristo
Telerik team
Jashwanth
Top achievements
Rank 1
Dess | Tech Support Engineer, Principal
Telerik team
Terje
Top achievements
Rank 2
Share this question
or