How to manage click event with 2 PushButton
Hi,
I have one GridGroupingControl that has 2 PushButton, I create a TableControlPushButtonClick
event, but I can not figure out how to know which button is clicked.
I can manage it with the code below, but when I use grouping, the numbers of column changes so e.Inner.ColIndex.
private void GgcDistribuidores_TableControlPushButtonClick(object sender, Syncfusion.Windows.Forms.Grid.Grouping.GridTableControlCellPushButtonClickEventArgs e)
{
GridRecordRow rec = this.ggcDistribuidores.Table.DisplayElements[e.Inner.RowIndex] as GridRecordRow;
DataRowView dr = rec.GetData() as DataRowView;
if (rec != null)
{
dr = rec.GetData() as DataRowView;
if (e.Inner.ColIndex == ggcDistribuidores.TableDescriptor.VisibleColumns.IndexOf("Detail")+1)
{
// Button Detail
}
if (e.Inner.ColIndex == ggcDistribuidores.TableDescriptor.VisibleColumns.IndexOf("General")+1)
{
// Button General
}
}
}
SIGN IN To post a reply.
3 Replies
AR
Arulpriya Ramalingam
Syncfusion Team
April 12, 2018 11:20 AM UTC
Hi Jorge,
Thanks for using Syncfusion products.
By default, the indent columns will be added to the grid based on the grouped columns count when the columns are grouped. So, that the actual index of the columns will be varies from the visible columns index. Please make use any one of the below suggestions to identify the button clicks,
Suggestion 1
In order to identify the column of current cell, the Style of the cell can be retrieved by using the GetTableViewStyleInfo() method to get the column name. Please refer the below code and sample.
Code example
|
//Event triggering
gridGroupingControl1.TableControlPushButtonClick += GridGroupingControl1_TableControlPushButtonClick;
//Event customization
private void GridGroupingControl1_TableControlPushButtonClick(object sender,GridTableControlCellPushButtonClickEventArgs e)
{
//Suggestion 1
GridTableCellStyleInfo style = e.TableControl.GetTableViewStyleInfo(e.Inner.RowIndex, e.Inner.ColIndex);
if (style.TableCellIdentity.Column.Name == "Details")
{
// Button Detail
}
if (style.TableCellIdentity.Column.Name == "General")
{
// Button General
}
} |
Suggestion 2
The FieldToColIndex() method can be used to get the exact index of particular column by using the visible columns index. Refer to the below code example
Code example
|
//Event triggering
gridGroupingControl1.TableControlPushButtonClick += GridGroupingControl1_TableControlPushButtonClick;
//Event customization
private void GridGroupingControl1_TableControlPushButtonClick(object sender,GridTableControlCellPushButtonClickEventArgs e)
{
//Suggestion 2
GridRecordRow rec = this.gridGroupingControl1.Table.DisplayElements[e.Inner.RowIndex] asGridRecordRow;
DataRowView dr = rec.GetData() as DataRowView;
if (rec != null)
{
dr = rec.GetData() as DataRowView;
//To get the index of the column.
int details = gridGroupingControl1.TableDescriptor.VisibleColumns.IndexOf("Details");
//To get the actual index of the column in view
int detailsIndex = gridGroupingControl1.TableDescriptor.FieldToColIndex(details);
int general = gridGroupingControl1.TableDescriptor.VisibleColumns.IndexOf("General");
int generalIndex = gridGroupingControl1.TableDescriptor.FieldToColIndex(general);
if (e.Inner.ColIndex == detailsIndex)
{
// Button Detail
}
if (e.Inner.ColIndex == generalIndex)
{
// Button General
}
}
} |
Sample link: http://www.syncfusion.com/downloads/support/directtrac/general/ze/ColumnIndex-1333829479
Regards,
Arulpriya
JO
Jorge
April 12, 2018 06:43 PM UTC
Excellent!
Thanks a lot!
SN
Sindhu Nagarajan
Syncfusion Team
April 13, 2018 04:06 AM UTC
Hi Jorge,
Thanks for the update.
We are glad to hear that the provided solution resolved your scenario. Please let us know if you have any other queries.
Regards,
Sindhu
SIGN IN To post a reply.
- 3 Replies
- 3 Participants
-
JO Jorge
- Apr 11, 2018 02:02 PM UTC
- Apr 13, 2018 04:06 AM UTC