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
close icon

PushButton cell type with dynamic button text and handler

We are using v15.2.0.40 of the GridGroupingControl and wish to have one column be a pushbutton. The text for the pushbutton should be the text value that is in the datasource (in our case a List<T>). This way each button of each row shows the value for that row in the column. The handler for the button should pass the value of the cell so we can generate a dynamic link when the button is pressed.

I have changed the cell type to pushbutton for the column under AnyRecordFieldCell and push buttons appear, but the face is blank. Also, which event should I be capturing when the users clicks on the button that will give me access to the value so we can generate a dynamic link from there.

Thanks!

6 Replies

MG Mohanraj Gunasekaran Syncfusion Team August 3, 2017 10:03 AM UTC

Hi John,   
   
Thanks for using Syncfusion product.   
   
In order to get the push button cell value underlying data source when click on the push button cell, you can use the CellValue property in TableControlCellButtonClicked event. Please refer to the below code example,   
   
Code example   
this.gridGroupingControl1.TableControlCellButtonClicked += gridGroupingControl1_TableControlCellButtonClicked;   
   
void gridGroupingControl1_TableControlCellButtonClicked(object sender,GridTableControlCellButtonClickedEventArgs e)   
{   
    GridTableCellStyleInfo style = e.TableControl.GetTableViewStyleInfo(e.Inner.RowIndex, e.Inner.ColIndex);   
    MessageBox.Show("Push button cell value: " + style.CellValue.ToString());   
}   
   
   
Please refer the below UG link   
   
Suggestion 2:   
If you want to set the cell value for push button text, you can use the Description and Cell Value property in QueryCellStyleInfo event. Please refer to the below code example and sample,   
   
Code example   
this.gridGroupingControl1.QueryCellStyleInfo += gridGroupingControl1_QueryCellStyleInfo;   
   
void gridGroupingControl1_QueryCellStyleInfo(object sender, GridTableCellStyleInfoEventArgs e)   
{   
    if (e.TableCellIdentity == null || e.TableCellIdentity.Column == null)   
        return;   
   
    if (e.TableCellIdentity.Column.Name == "Country")   
    {   
        e.Style.Description = e.Style.CellValue.ToString();   
        e.Style.HorizontalAlignment = GridHorizontalAlignment.Center;   
    }   
}   
   
   
Note:   
If you have used the QueryCellStyleInfo event to set the text for button, you can get the cell value using Button.Text property in TableControlCellButtonClicked event. Please refer to the below code example,   
   
Code example   
void gridGroupingControl1_TableControlCellButtonClicked(object sender,GridTableControlCellButtonClickedEventArgs e)   
{   
    MessageBox.Show("Push button cell value: " + e.Inner.Button.Text);   
}   
   
   
   
Sample link: GridGroupingControl   
   
Regards,   
Mohanraj G   
 



JV John Virgolino August 7, 2017 05:29 PM UTC

Mohanraj,

This worked perfectly! Thanks for the help!



MG Mohanraj Gunasekaran Syncfusion Team August 8, 2017 08:58 AM UTC

Hi John, 
 
Thanks for your update. 
 
We are glad to know that your reported problem has resolved. 
 
Please let us know if you have any further assistance. 
 
Regards, 
Mohanraj G 



SU Susheel December 5, 2018 05:29 PM UTC

Hi Mohanraj G,

Iam trying get push button text from grid grouping control, on save button click, please help.

Thanks
Susheel


SU Susheel December 5, 2018 05:35 PM UTC

My requirement is to loop throgh grid grouping control rows on save button click, and get button text to perform operation.

please help asap.


AA Arulraj A Syncfusion Team December 6, 2018 05:29 AM UTC

Hi Susheel, 

Thanks for your update. 

To iterate the rows through button click, you could use the Records collection and Record.GetValue method in TableControlCellButtonClicked event. Please refer the following code example and the sample. 
 
Code example 
this.gridGroupingControl1.TableControlCellButtonClicked += gridGroupingControl1_TableControlCellButtonClicked; 
 
void gridGroupingControl1_TableControlCellButtonClicked(object sender, GridTableControlCellButtonClickedEventArgs e) 
{ 
    //To get the button text 
    string text = e.Inner.Button.Text; 
    //To iterate the rows 
    for (int i = 0; i < this.gridGroupingControl1.Table.Records.Count; i++) 
    { 
        var record = this.gridGroupingControl1.Table.Records[i]; 
        //To iterate the columns 
        foreach (var column in this.gridGroupingControl1.TableDescriptor.Columns) 
        { 
            //To get the cellvalue 
            string cellvalue = record.GetValue(column.Name).ToString(); 
        } 
    } 
} 
                 

Arulraj A 


Loader.
Live Chat Icon For mobile
Up arrow icon