Thursday, March 17, 2011

CDC Software Pivotal CRM 6.0: How to change form title programmatically.

It's not easy as I thought.

I need to change a new form title that always set to "New".
And I don't want to change language strings and add parameters like "My new %1"...

FormView.FormTitle is read only property.
Also, FormView class marked as internal class that implements IFormView interface.
So, we can't access directly to to the internal class from another assembly.
But there is a nice solution that always works - Reflection.

 public override void OnFormInitialized()
{
  //Get user defined form title
  string userDefinedFormTitle = Convert.ToString(this.FormControl.WindowsControl.GetType().GetProperty("FormTitle").GetValue(this.FormControl.WindowsControl, null));

            
  //Set new form title
  this.FormView.GetType().GetProperty("FormTitle").SetValue(this.FormView, originalFormTitle, null);
 }


Reflection rules!
Max

No comments:

Post a Comment