Image CWR Mobility Wiki
This article applies to:
  • CWR Mobile CRM 4.2 Windows Mobile

The sample below is a template which can be used as the basis for custom control development

public class MyControl : IFormControl
{
  public MyControl()
  {
  }
  private IFormContext2 _context;

  public void Configure(IFormContext2 context, string controlName, string configurationXml)
  {
    _context = context;

    _context.SourceRecordChanged += MyControl_SourceRecordChanged;
    _context.FormChanged += MyControl_FormChanged;
  }

  public void MyControl_SourceRecordChanged(object sender, EventArgs e)
  {
    if (_context.ObjectId == Guid.Empty)
    {
      //This is a new record

      object value = _context.GetValue("fieldname");

      if (value == null)
      {
        //The record has no value set a the default
      }
      else
      {
        //The record has a value from a mapping or passed in as a default)
      }
    }
    else
    {
      //This is an existing record

      object value = _context.GetValue("fieldname");

      if (value != null)
      {
        //The field has a value
      }
    }
  }

  public void MyControl_FormChanged(object sender, FormChangedEventArgs e)
  {
    if (e.Fieldname == "fieldname")
    {
      //Some other control has changed the value; update accordingly
      //Note: this event is also trigger if this controls calls the context.SetValue method
      //The IFormContext2.SetValue method should not be called from this method on the same field unless the value has actually changed.
    }
  }

  public bool Validate(out string errMessage)
  {
    // Perform Validation here

    if (!IsValid())
    {
      errMessage = "Value is not valid";
      return false;
    }

    return true;
  }

  public object SaveState()
  {
    //Save all state related to the current form so the control can be restored using the loadstate
  }
  public void LoadState(object stateValue)
  {
    //Revert the control to the state at the time SaveState was called
  }
}

ScrewTurn Wiki version 2.0.35. This Wiki contains 59 pages.