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

Setting text to Gridview Command button for a new row

3 Answers 331 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Shamjith
Top achievements
Rank 1
Shamjith asked on 09 Dec 2009, 03:09 PM
 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

3 Answers, 1 is accepted

Sort by
0
Svett
Telerik team
answered on 11 Dec 2009, 09:32 AM
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.
0
Gone2TheDogs
Top achievements
Rank 1
Iron
Veteran
answered on 30 Jan 2019, 05:19 PM

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?

 

0
Dess | Tech Support Engineer, Principal
Telerik team
answered on 01 Feb 2019, 03:00 PM
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.
Tags
GridView
Asked by
Shamjith
Top achievements
Rank 1
Answers by
Svett
Telerik team
Gone2TheDogs
Top achievements
Rank 1
Iron
Veteran
Dess | Tech Support Engineer, Principal
Telerik team
Share this question
or