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

Display PushButton conditionally

I am adding a PushButton to an UnboundField through the GridTableDescriptor. I do not want the push button to display on each record. Is there a way I can hide the PushButton based on a condition in my child table data?

Thank you,
Josh

1 Reply

RA Rajagopal Syncfusion Team June 6, 2007 09:01 PM UTC

Hi Josh,

You can handle the QueryCellStyleInfo event to do this. In the event handler code, you can loop through the records of the childtable untill specified condition is satisfied and then hide the pushbutton in the parentrecord by setting the celltype to textbox. Please refer the attached sample for more details. Below is the code snippet.

void gridGroupingControl1_QueryCellStyleInfo(object sender, GridTableCellStyleInfoEventArgs e)
{
if (e.TableCellIdentity.TableCellType == GridTableCellType.RecordFieldCell
|| e.TableCellIdentity.TableCellType == GridTableCellType.AlternateRecordFieldCell
&& e.Style.CellType == "PushButton")
{
Element el = e.TableCellIdentity.DisplayElement;
Record rec = el.ParentRecord;
if (rec.HasNestedTables)
{
foreach (GridRecord gr in el.ParentRecord.NestedTables[0].ChildTable.Records)
{
bool chk = (bool)gr.GetValue("Check");
if (chk)
{
e.Style.CellType = "TextBox";
break;
}
}
}
}
}
void gridGroupingControl1_TableControlCellButtonClicked(object sender, GridTableControlCellButtonClickedEventArgs e)
{
GridTableCellStyleInfo style = e.TableControl.GetTableViewStyleInfo(e.Inner.RowIndex, e.Inner.ColIndex);
if (style.TableCellIdentity.TableCellType != GridTableCellType.RecordPlusMinusCell)
{
string str = string.Format("Clicked on recordindex: {0}", style.TableCellIdentity.DisplayElement.GetRecord().GetSourceIndex());
MessageBox.Show(str, "Click!", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
}

Here is a sample http://websamples.syncfusion.com/samples/Grid.Windows/F62028/main.htm

Regards,
Rajagopal

Loader.
Live Chat Icon For mobile
Up arrow icon