Using group controls to display and edit attributes

The application framework exposes the group control components used to build the ready-to-deploy windows mobile application. Since these components are used extensively by the application, your extensions will have the same look and user experience as the application. By leveraging these components, you can reduce development time and costs, and provide a seamless integration.

To show attributes for a feature or to allow your user to edit attributes, use the built-in ViewAttributesPage or EditAttributesPage.

If you intend to build other pages that incorporate tabular information that you want to show your user, or allow the user to modify that information, there is a set of out-of-the-box groups you can use. The concept of groups is widely used within the application when it presents information to your user or collects information from your user. A group is essentially a collection of user interface (UI) controls grouped together. You can create a GroupView, add it to your page, then add different groups to the GroupView.

The following screen capture shows ReadOnlyAttributeGroup used in ViewAttributesPage for displaying a feature's attributes:

View Attributes page of Windows mobile application

The following code illustrates how to create a groupview and add different types of groups to a page and allows a user to edit each of them. For more code details, and to see the group's work in action, see the Sample_SimpleDataEntryTask sample.

private void CreateGroups()
    {
      // Create GroupView
      GroupView gv = new GroupView();
      ReadOnlyAttributeGroup employeeIDGroup = new ReadOnlyAttributeGroup("Employee ID", "351024");
      gv.Groups.Add(employeeIDGroup);
 
      // Department
      string[] departments = new string[] { "Human Resource", "Software Development", "Software Products", "Facilities", "System", "Sales", "Marketing"};
      SelectionGroup<string> departmentGroup = new SelectionGroup<string>("Department", "Software Development", departments, "Software Development", "Software Development");
      gv.Groups.Add(departmentGroup); 

      // Photo
      Group pictureGroup = new Group();
      PictureItem picGroupItem = new PictureItem();
      picGroupItem.Bitmap = (Bitmap)Resources.User;
      pictureGroup.Items.Add(picGroupItem);
      gv.Groups.Add(pictureGroup); 

      // First Name
      StringAttributeGroup firstNameGroup = new StringAttributeGroup("First Name", "Richard", true, 30);
      gv.Groups.Add(firstNameGroup); 

      // Last Name
      StringAttributeGroup lastNameGroup = new StringAttributeGroup("Last Name", "Harris", true, 30);
      gv.Groups.Add(lastNameGroup); 

      // Date of Birth
      DateAttributeGroup dobGroup = new DateAttributeGroup("Date of Birth", DateTime.Now);
      gv.Groups.Add(dobGroup); 

      // Gender
      RadioGroup genderGroup = new RadioGroup("Gender", new string[] { "Male", "Female" });
      genderGroup.CheckedItem = "Male";
      gv.Groups.Add(genderGroup);

       // Distance from work
      DistanceGroup distanceGroup = new DistanceGroup("Distance from work", 5.25, ESRI.ArcGIS.Mobile.SpatialReferences.Unit.Mile);
      gv.Groups.Add(distanceGroup); 

      // Phone Number
      StringAttributeGroup phoneGroup = new StringAttributeGroup("Phone", "(909) 793-2853", false);
      gv.Groups.Add(phoneGroup);

       // Email
      StringAttributeGroup emailGroup = new StringAttributeGroup("E-mail", "support@esri.com", true);
      gv.Groups.Add(emailGroup); 

      this.Controls.Add(gv);
      gv.Dock = DockStyle.Fill; 
      this.Controls.SetChildIndex(gv, 0);
    }

As seen in the previous code, you can use different types of groups provided by the application framework. If, however, you have additional requirements, you can also build your own group that implements a custom UI as well as functionality to fit your needs.

The following code illustrates how to create your own group items to deal with BLOB fields that store audio information. This code sample assumes the audio column name starts with audio_.

ViewAttributesPage.CreatingViewGroups += new EventHandler<CreatingViewGroupsEventArgs>(ViewAttributesPage_CreatingViewGroups);

    private void ViewAttributesPage_CreatingViewGroups(object sender, CreatingViewGroupsEventArgs e)
    {
      FeatureDataReader reader = e.Feature.GetDataReader();
      try
      {
        reader.ReadFirst();
        foreach (DataColumn dc in reader.FeatureLayer.Columns)
        {
          if (dc.DataType == typeof(byte[]) && dc.ColumnName.ToLower().IndexOf("audio_") == 0)
          {
            FeatureColumnGroup group = new FeatureColumnGroup(e.Feature, dc); 
            TextItem headerItem = new TextItem(dc.ColumnName);
            headerItem.Selectable = false;
            headerItem.Style = TextItemStyle.Bold;
            group.Items.Add(headerItem); 

            bool hasAudio = false;
            if (reader[dc.ColumnName] != DBNull.Value)
            {
              byte[] bytes = (byte[])reader[dc.ColumnName];
              if (bytes != null && bytes.Length > 0)
              {
                LinkItem lgi = new LinkItem("Play Audio");
                lgi.Selectable = true;
                lgi.Activated += new EventHandler(ViewPagePlayAudioLinkActivated);
                group.Items.Add(lgi);
                hasAudio = true;
              }
            } 

            if (!hasAudio)
            {
              TextItem tgi = new TextItem("<No Audio Recorded>");
              tgi.Selectable = false;
              group.Items.Add(tgi);
            } 

            e.Groups.Add(group);
          }
        }
      }
      finally
      {
        if (reader != null)
        {
          // close the reader
          reader.Close();
          reader.Dispose();
          reader = null;
        }
      }
    } 

  public class FeatureColumnGroup : Group
  {
    private DataColumn m_dc;
    private Feature m_feature; 

    public FeatureColumnGroup(Feature feature, DataColumn dc)
      : base()
    {
      m_dc = dc;
      m_feature = feature;
    } 

    public DataColumn DataColumn
    {
      get { return m_dc; }
    } 

    public Feature Feature
    {
      get { return m_feature; }
    }
  }

1/7/2015