this.gridControl1.ColStyles[5].CellType = "PushButton";
this.gridControl1.ColStyles[5].Description = "Disable";
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";
}
}
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
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;
}
} |
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;
}
} |