Adding a button column
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?
SIGN IN To post a reply.
8 Replies
RC
Rajadurai C
Syncfusion Team
October 19, 2009 01:55 PM UTC
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.
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.
Regards,
Rajadurai
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
JL
Jason Lui
October 19, 2009 02:13 PM UTC
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.
JL
Jason Lui
October 19, 2009 02:20 PM UTC
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.
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.
RC
Rajadurai C
Syncfusion Team
October 19, 2009 02:23 PM UTC
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
To set the text for the pushbutton, make use of Description property. The button click event can be handled through TableControlPushButtonClick event.
Regards,
Rajadurai
QU
QLT User
September 18, 2017 04:14 PM UTC
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
AR
Arulpriya Ramalingam
Syncfusion Team
September 19, 2017 10:27 AM UTC
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
RR
Rija Rabe
April 12, 2019 07:18 AM UTC
Hello,
Is there a way to only put a button on a summary row instead of all the rows ?
Regards!
SR
Sabaridass Ramamoorthy
Syncfusion Team
April 15, 2019 12:38 PM UTC
Hi Rija,
In order to add the push button for summary cells, you need to use the TableCellIdentity.DisplayElement.Kind property in QueryCellStyleInfo event. Please refer the following code example.
C#
|
this.gridGroupingControl1.QueryCellStyleInfo += GridGroupingControl1_QueryCellStyleInfo;
private void GridGroupingControl1_QueryCellStyleInfo(object sender, GridTableCellStyleInfoEventArgs e)
{
int fieldIndex = this.gridGroupingControl1.TableDescriptor.Columns.IndexOf("Button");
int colIndex = this.gridGroupingControl1.TableDescriptor.FieldToColIndex(fieldIndex);
//To restrict the button
if(e.TableCellIdentity != null && e.TableCellIdentity.RowIndex > 0
&& e.TableCellIdentity.DisplayElement.Kind == DisplayElementKind.Summary && e.TableCellIdentity.ColIndex == colIndex)
{
e.Style.CellType = "PushButton";
e.Style.Description = "ON";
e.Handled = true;
}
} |
Please get back to us if you need any further assistance on this.
Regards,
Sabaridass R
SIGN IN To post a reply.
- 8 Replies
- 6 Participants
-
JL Jason Lui
- Oct 16, 2009 09:06 PM UTC
- Apr 15, 2019 12:38 PM UTC