We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date

on TableControlPushButtonClick pushbutton text change or disable


hello sir/madam
i am using SyncfusionGridGroupingControl and inside one push button.
i want to change pushbutton text on TableControlPushButtonClick using c# code,so please help me how can i do

thank u in advance.

5 Replies

AR Arulpriya Ramalingam Syncfusion Team July 3, 2017 12:00 PM UTC

Hi ketan, 

Thank you for using Syncfusion products. 

In order to change the Button Text when the button is clicked, the QueryCellStyleInfo and TableControlPushButtonClick events can be used. In QueryCellStyleInfo event the Description property can be used to set the PushButtonText. Please make use of below code and sample, 

//Event Triggering 
gridGroupingControl1.QueryCellStyleInfo += GridGroupingControl1_QueryCellStyleInfo; 

//Event Customization 
private void GridGroupingControl1_QueryCellStyleInfo(object sender, GridTableCellStyleInfoEventArgs e) 
{ 
    if(e.TableCellIdentity != null && e.TableCellIdentity.Column != null && e.TableCellIdentity.Column.MappingName == "Button") 
    { 
        string key = e.TableCellIdentity.RowIndex.ToString() + e.TableCellIdentity.ColIndex.ToString(); 
        if (description.Count > 0 && description.ContainsKey(key)) 
        { 
            string value = description[key]; 
            if (description.Count > 0 && !String.IsNullOrEmpty(value)) 
            { 
                e.Style.Description = value; 
            } 
        } 
    } 
} 
//Event Triggering 
gridGroupingControl1.TableControlPushButtonClick += GridGroupingControl1_TableControlPushButtonClick; 
 
//Event Customization 
private void GridGroupingControl1_TableControlPushButtonClick(object sender, GridTableControlCellPushButtonClickEventArgs e) 
{ 
    rowIndex = e.Inner.RowIndex; 
    colIndex = e.Inner.ColIndex; 
    string key = rowIndex.ToString() + colIndex.ToString(); 
    if (!description.ContainsKey(key)) 
    { 
        description.Add(key, "Start"); 
    } 
    else 
    { 
        string value = description[key]; 
        if (value == "Start") 
            description[key] = "Stop"; 
        else 
            description[key] = "Start"; 
    } 
} 

 
Note: 
The TableControlCellButtonClicked event can also be used instead of TableControlPushButtonClick event. 


Regards, 
Arulpriya 



SU Susheel December 4, 2018 07:40 AM UTC

Hi AnuPriya,

can you please share a sample on how to change button text in grid grouping control with dynamic grid binding.

Thanks
Susheel


AA Arulraj A Syncfusion Team December 4, 2018 12:06 PM UTC

Hi Susheel, 

Thanks for using Syncfusion product. 

To change the button text for dynamic grid binding, you could use the Description property in QueryCellStyleInfo event. Please refer the following code example, 

Code example 
this.gridGroupingControl1.QueryCellStyleInfo += GridGroupingControl1_QueryCellStyleInfo; 
 
private void GridGroupingControl1_QueryCellStyleInfo(object sender, GridTableCellStyleInfoEventArgs e) 
{ 
    if (e.TableCellIdentity == null || e.TableCellIdentity.Column == null) 
        return; 
 
    if (e.TableCellIdentity.Column.Name == "Button" && e.TableCellIdentity.DisplayElement.Kind == Syncfusion.Grouping.DisplayElementKind.Record) 
    { 
        var record = e.TableCellIdentity.DisplayElement.GetRecord(); 
        string text = record.GetValue("Button").ToString(); 
        e.Style.Description = text; 
    } 
} 
 
To change the button text when clicking, you could use the PushButtonClick event. Please refer the following code example, 

Code example 
this.gridGroupingControl1.TableControlPushButtonClick += GridGroupingControl1_TableControlPushButtonClick; 
 
private void GridGroupingControl1_TableControlPushButtonClick(object sender, GridTableControlCellPushButtonClickEventArgs e) 
{ 
    GridTableCellStyleInfo style = e.TableControl.GetTableViewStyleInfo(e.Inner.RowIndex, e.Inner.ColIndex); 
    var record = style.TableCellIdentity.DisplayElement.GetRecord(); 
    if (record != null) 
    { 
        string text = style.CellValue.ToString(); 
        if (text.Equals("Start")) 
            record.SetValue("Button", "Stop"); 
        else if (text.Equals("Stop")) 
            record.SetValue("Button", "Start"); 
        else if (text.Equals("On")) 
            record.SetValue("Button", "Off"); 
        else if (text.Equals("Off")) 
            record.SetValue("Button", "On"); 
        else if (text.Equals("Click")) 
            record.SetValue("Button", "Clicked"); 
        else if (text.Equals("Clicked")) 
            record.SetValue("Button", "Click"); 
        else if (text.Equals("Press")) 
            record.SetValue("Button", "Pressed"); 
        else if (text.Equals("Pressed")) 
            record.SetValue("Button", "Press"); 
    } 
} 
 
 
Arulraj A 



SU Susheel December 4, 2018 01:58 PM UTC

Thank you Anulraj, worked perfectly :-)

Regards,
Susheel


AA Arulraj A Syncfusion Team December 5, 2018 06:53 AM UTC

Hi Susheel,  
 
Thanks for the update. 
 
We are glad to know that the provided solution worked at your end. Please let us know if you have any further queries on this. We are happy to help you. 
 
Regards, 
Arulraj A 


Loader.
Up arrow icon