Setting text to Gridview Command button for a new row

4 posts, 0 answers
  1. Shamjith
    Shamjith avatar
    15 posts
    Member since:
    Sep 2008

    Posted 09 Dec 2009 Link to this post

     public partial class Form1 : Form  
        {  
            private readonly DataTable dtMain;  
     
            public Form1()  
            {  
                InitializeComponent();  
                dtMain = new DataTable();  
                 
                CreateSampleTable();  
                InsertValues();  
     
                radGridView1.DataSource = dtMain;  
            }  
     
            private void CreateSampleTable()  
            {  
                dtMain.Columns.Add(new DataColumn("column1", typeof(String)));  
                dtMain.Columns.Add(new DataColumn("column2", typeof(String)));  
                dtMain.Columns.Add(new DataColumn("column3", typeof(String)));  
            }  
     
            private void InsertValues ()  
            {  
                var drMain = dtMain.NewRow();  
                drMain["column1"] = "1";  
                drMain["column2"] = "One";  
                dtMain.Rows.Add(drMain);  
     
                drMain = dtMain.NewRow();  
                drMain["column1"] = "2";  
                drMain["column2"] = "Two";  
                dtMain.Rows.Add(drMain);  
     
                drMain = dtMain.NewRow();  
                drMain["column1"] = "3";  
                drMain["column2"] = "Three";  
                dtMain.Rows.Add(drMain);  
            }  
     
            private void radGridView1_RowFormatting(object sender, Telerik.WinControls.UI.RowFormattingEventArgs e)  
            {  
                var gvri = e.RowElement.RowInfo;  
     
                var rbApply = gvri.Cells["column3"] != null && gvri.Cells["column3"].CellElement != null ?  
                              gvri.Cells["column3"].CellElement.Children[0] as RadButtonElement : null;  
     
                if (rbApply != null)  
                {  
                    rbApply.Text = "Apply";  
                    rbApply.TextAlignment = ContentAlignment.MiddleCenter;  
                }  
            }  
            
        } 
    Hi,

          I have a rad gridview windows control with two text columns and a button column. AllowAddNewRow is set to "True" for the Gridview. I have set the Text property of the button to "Apply" in RowFormatting event.There are three rows in the datasource.When the application is run, we can see the button text assigned for those three rows. But the RowFormatting event is not fired when the new row is selected, So the newly created row will have a button with blank text. Please help me on this.

    Regards
    Shamjith
  2. Svett
    Admin
    Svett avatar
    728 posts

    Posted 11 Dec 2009 Link to this post

    Hello Shamjith,

    When you create your button use the instance of GridViewCommandColumn:

    GridViewCommandColumn column = new GridViewCommandColumn("Settings", "Settings");
    column.DefaultText = "Apply";
    column.UseDefaultText = true;
    this.radGridView1.Columns.Add(column);

    Regards,

    Svett
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
  3. Gone2TheDogs
    Gone2TheDogs avatar
    65 posts
    Member since:
    May 2016

    Posted 30 Jan 2019 Link to this post

    I tried using the Property Builder and setting the properties for my button columns, but it didn't work. Can this only be done during run-time?

     

  4. Dess | Tech Support Engineer, Sr.
    Admin
    Dess | Tech Support Engineer, Sr.  avatar
    3754 posts

    Posted 01 Feb 2019 Link to this post

    Hello, Bob,       

    Following the provided information, I was unable to reproduce the issue you are facing. Please refer to the below screenshots illustrating the behavior on my end with the specified version. I have attached my sample project. Am I missing something? Could you please specify the exact steps how to reproduce the problem?





    I am looking forward to your reply.

    Regards,
    Dess | Tech Support Engineer, Sr.
    Progress Telerik
    Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
Back to Top