Here is the code snippet…
private void AutoFormat()
{
try
{
AutoFormatRule afr;
TableView tv;
tv = applicationObject.ActiveExplorer().CurrentView;
MessageBox.Show(tv.AutoFormatRules.Count.ToString());
for (int i=1;i<=tv.AutoFormatRules.Count;i++)
{
AutoFormatRule rl = tv.AutoFormatRules[i];
if(rl.Name=="TestAFRule")
{
tv.AutoFormatRules.Remove(i);
MessageBox.Show("Deleted" + rl.Name);
}
}
afr = tv.AutoFormatRules.Add("TestAFRule");
afr.Font.Color = OlColor.olColorRed;
afr.Enabled = true;
tv.Save();
tv.Apply();
MessageBox.Show("Done");
}
catch(System.Exception ex)
{
MessageBox.Show("Err:" + ex.Message);
}
}