There is a function called: InRepeatedGroupHeader. If I apply formula to the Suppress option of the group in which header is defined and then in the code change it, it works.
var formulaField = mainSubreport.DataDefinition.FormulaFields["RepeatHeader"];
formulaField.Text = "if inrepeatedgroupheader then TRUE ELSE FALSE";