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.
Unfortunately, activation email could not send to your email. Please try again.

Adding a button column

Thread ID:

Created:

Updated:

Platform:

Replies:

90781 Oct 16,2009 05:06 PM Sep 19,2017 06:27 AM Windows Forms 6
loading
Tags: Grouping
Jason Lui
Asked On October 16, 2009 05:06 PM

Is there anyway to add a button column? I want to add a 'On' and 'Off' button for each row. If so, how do I hook into the click event?

Rajadurai C [Syncfusion]
Replied On October 19, 2009 09:55 AM

Hi Jason,

Thanks for your interest in Syncfusion Products.

A column in gridcontrol can be set with buttons through the use of "PushButton" celltype with the following code.

this.gridControl1.ColStyles[5].CellType = "PushButton";
this.gridControl1.ColStyles[5].Description = "Disable";

The click in this button trigger the PushButtonClick event. This event provides properties to access the index of the cell whose button has been clicked.

Here is some code for your reference handled in this event.

this.gridControl1.PushButtonClick += new GridCellPushButtonClickEventHandler(gridControl1_PushButtonClick);

void gridControl1_PushButtonClick(object sender, GridCellPushButtonClickEventArgs e)
{
if (this.gridControl1.RowStyles[e.RowIndex].Enabled && this.gridControl1[e.RowIndex, e.ColIndex].Description == "Disable")
{
this.gridControl1.RowStyles[e.RowIndex].Enabled = false;
this.gridControl1.CurrentCell.Refresh();
this.gridControl1[e.RowIndex, e.ColIndex].Description = "Enable";
}
else
{
this.gridControl1.RowStyles[e.RowIndex].Enabled = true;
this.gridControl1[e.RowIndex, e.ColIndex].Description = "Disable";
}
}

Regards,
Rajadurai

Jason Lui
Replied On October 19, 2009 10:13 AM

Thanks for the reply. I apologize I didn't mention it in my original post, but I would like this for a grid grouping control. Was the code you posted above for another grid control? I was not able to see the properties in my IDE.

Jason Lui
Replied On October 19, 2009 10:20 AM

I was able to use:

gridGroupingControl.TableDescriptor.Columns["Test"].Appearance.AnyRecordFieldCell.CellType = "PushButton";

to achieve partly what I needed, but how do I set the text in the button? I tried setting the cell value property but that didn't do anything.

Rajadurai C [Syncfusion]
Replied On October 19, 2009 10:23 AM

Hi Jason,

To set the text for the pushbutton, make use of Description property. The button click event can be handled through TableControlPushButtonClick event.

Regards,
Rajadurai

QLT User
Replied On September 18, 2017 12:14 PM

1. how would you get the current record or the data from another cell in that row with the
GridCellPushButtonClickEventHandler.

2.how do i make sure the header cell does not show a button in gridgroupingcontrol


Arulpriya Ramalingam [Syncfusion]
Replied On September 19, 2017 06:27 AM

Hi Customer, 
  
Thanks for your interest in Syncfusion products.   
  
Query   
Response   
1. how would you get the current record or the data from another cell in that row with the    
GridCellPushButtonClickEventHandler.   
The CurrentRecord can be retrieved from the GridTableCellStyleInfo when the push button of a cell is clicked. The GetTableViewStyleInfo() method can be used to get the Style of the current cell and the GetRecord() method of Element can be used to get the current record. Please refer to below code and KB link,   
  
//Event Subscription   
this.gridGroupingControl1.TableControlPushButtonClick += GridGroupingControl1_TableControlPushButtonClick;   
   
//Event Customization   
private void GridGroupingControl1_TableControlPushButtonClick(object sender,GridTableControlCellPushButtonClickEventArgs e)   
{   
    GridTableCellStyleInfo style =this.gridGroupingControl1.TableControl.GetTableViewStyleInfo(e.Inner.RowIndex, e.Inner.ColIndex);   
    GridTableCellStyleInfoIdentity id = style.CellIdentity as GridTableCellStyleInfoIdentity;   
    //To get the current record   
    Record record = id.DisplayElement.GetRecord();   
    if (record != null)   
    {   
        string cellValue = record.GetValue("DateTime").ToString();   
        MessageBox.Show(cellValue);   
    }   
}   
  
2.how do i make sure the header cell does not show a button in gridgroupingcontrol   
Suggestion 1   
   
If you want to add push buttons only for record cells, use the AnyRecordFieldCell Property of GridTableCellAppearence to add the push button cell types only to the record rows. So, the push button will not be set for column headers. Please refer to the below code,   
  
//To add the push button only for the record fields   
this.gridGroupingControl1.TableDescriptor.Columns["Button"].Appearance.AnyRecordFieldCell.CellType = GridCellTypeName.PushButton;   
Suggestion 2   
The QueryCellStyleInfo event can also be used to add the push buttons only to the record field cells. In that event the CellType property can be used to restrict the push button for header cells. Please refer to the below code and sample,   
   
//Event Subscription   
this.gridGroupingControl1.QueryCellStyleInfo += GridGroupingControl1_QueryCellStyleInfo;   
   
//Event Customization   
private void GridGroupingControl1_QueryCellStyleInfo(object sender, GridTableCellStyleInfoEventArgse)   
{   
    //To restrict the button    
    if(e.TableCellIdentity.RowIndex > 0 && e.TableCellIdentity.Column !=null && e.TableCellIdentity.Column.Name == "Button" && e.Style.CellType != "ColumnHeaderCell")   
    {   
        e.Style.CellType = "PushButton";   
        e.Style.Description = "ON";   
        e.Handled = true;   
    }   
}   
  
  
Regards,   
Arulpriya   


CONFIRMATION

This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.

;