Select to view content in your preferred language

EditAttributesDialog Refresh Problem - Windows Mobile

828
5
07-29-2011 12:26 PM
JonathanCarewick
Emerging Contributor
Hi guys,

I'm hoping someone can help me out and also wondering if anyone else has come across this problem with auto populating fields in an EditAttributesDialog form.

What I need to accomplish:
Auto populate some fields (such as Date) any time an EditAttribuesDialog is used by the user. The fields would always be the same name, so there's no issue there.

What I've done so far:
I followed the AttributesExtension example and my project is now listening to the static event
EditAttributesDialog.CreatingEditGroups += new EventHandler<CreatingEditGroupsEventArgs>(EditAttributesPage_CreatingEditGroupsEvent);
just as that example does. I created a method that fires when this event occurs, and this is where I put the code in to auto populate the date field. If I launch my application with my current code, edit a point, hit save, it works great.

What I'm having a problem with:
When making edits on the point, viewing the form, the form doesn't display the information that I have auto populated. For instance, I make an edit, the form comes up, I scroll to where the date field is and it appears blank, yet if I click on it it's got the current date and time. If I hit back and don't even change the date using the calendar control the comes up... it refreshes no problem. Here's where my problem is, how do you refresh the display of this form? here's my entire CreatingEditGroupsEvent method:

private void EditAttributesPage_CreatingEditGroupsEvent(object sender, CreatingEditGroupsEventArgs e)
{
 try
 {
  FeatureDataRow fdr = e.FeatureDataRow;

  foreach (DataColumn dc in fdr.FeatureLayer.Columns)
  {
   // Auto Populate the DATE Field
   if (dc.ColumnName.ToLower().IndexOf("date") != -1)
   {
    fdr[dc.ColumnName] = DateTime.Now;
   }
  }
   
  if (sender is EditAttributesDialog)
  {
   // Refresh the Edit Dialog:
   EditAttributesDialog editDialog = (EditAttributesDialog)sender;

   // Attempt to refresh layout and display auto populated
   // None of these worked:
   //editDialog.Refresh();
   //editDialog.ResumeLayout();
   //editDialog.Update();
   //editDialog.Show();

   //editDialog.Focus();
   //editDialog.Activate();

   //editDialog.CreateGraphics();

   //editDialog.PerformAutoScale();

   //editDialog.Hide();
   //editDialog.Show();

   //MobileApplication.Current.CurrentForm.Refresh();

   //editDialog.On

   //editDialog.BringToFront();
  }

 }
 catch (Exception ex)
 {
  ESRI.ArcGIS.Mobile.Client.Dialogs.MessageDialog.Show(ex.Message, "ERROR Edit Attributes", MessageBoxButtons.OK);
 }

 
}




I'm pretty frustrated with it since it actually does work, but from a user's perspective they won't think it's working if I start auto populating other fields automatically through code.


Anyone have any ideas? Anyone ever come across this or something similar?
0 Kudos
5 Replies
AkhilParujanwala
Regular Contributor
Yes I have also had the same problem. I figured out 2 ways to refresh or work arounds.

1) When transitioning to the AttributesForm page, just before you transition to the form, I have a procedure which will auto populate all the necessary fields. So when the user sees the attributes forms, all information will be filled in. So by doing this it is a work around, meaning auto populate your fields before transitioning to the attributes form.

Yes, you cannot refresh the AttributesForm right when you are on it with even code. Yes, you can refresh the AttributesForm by loading a new form and then going back to the AttributesForm, this works because it does reload the form, but is not a suitable solution.

2) The trick to refreshing is to use Height and Width of the page, I am using this for my WPF.Map control to refresh the map. All I do is simply Height - 1 and it refreshes the map. I am assuming this could work for the attributes form, but I am not 100%. I also believe you are using the Mobile app, whereas I am using the WPF app.

Regardless, I hope the Height property can be used for the page in your app which will refresh the attributes form. You will also need to use Height + 1 to fix the page back to normal height. If you don't you form will become smaller every time you transition to it (maybe).
0 Kudos
JonathanCarewick
Emerging Contributor
Yes I have also had the same problem. I figured out 2 ways to refresh or work arounds.

1) When transitioning to the AttributesForm page, just before you transition to the form, I have a procedure which will auto populate all the necessary fields. So when the user sees the attributes forms, all information will be filled in. So by doing this it is a work around, meaning auto populate your fields before transitioning to the attributes form.

Yes, you cannot refresh the AttributesForm right when you are on it with even code. Yes, you can refresh the AttributesForm by loading a new form and then going back to the AttributesForm, this works because it does reload the form, but is not a suitable solution.

2) The trick to refreshing is to use Height and Width of the page, I am using this for my WPF.Map control to refresh the map. All I do is simply Height - 1 and it refreshes the map. I am assuming this could work for the attributes form, but I am not 100%. I also believe you are using the Mobile app, whereas I am using the WPF app.

Regardless, I hope the Height property can be used for the page in your app which will refresh the attributes form. You will also need to use Height + 1 to fix the page back to normal height. If you don't you form will become smaller every time you transition to it (maybe).



Thanks for the tips. I tried adjusting the height of the form and unfortunately, it didn't work. That' odd that you've experienced this problem on the Windows Side, I've developed similar auto populate extensions for WPF and they've all worked fine.

I don't know if this helps you, but all I do for my auto populate for the windows apps is monitor the static event EditFeatureAttribtesPage.ControlCreatingFeatureAttributes with the following method being executed:


        void m_FeaturesChanged_Event(object sender, EditFeatureAttributesPageEventArgs e)
        {
            try
            {
                Feature feature = e.Page.Feature;

                FeatureDataRow fdr = feature.FeatureDataRow;
                foreach (DataColumn dc in fdr.FeatureLayer.Columns)
                {
                    if (dc.ColumnName.ToLower().IndexOf("date") != -1)
                    {
                        fdr[dc.ColumnName] = DateTime.Now.ToString();
                    }
                }

            }
            catch (Exception ex)
            {
                // This happens, we just have to catch it so the application doesn't error out
                // A message box isn't necessary here since the user would ALWAYS see it.
            }
        }

0 Kudos
JonathanCarewick
Emerging Contributor
I found a workaround! This code only works on the Windows Mobile side, but it works rather nice. Here's my method that's fired (I'm listening to the EditAttributes Event as described above):


        /// <summary>
        /// Event fired when Edit Attributes Page is opened
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void EditAttributesPage_CreatingEditGroupsEvent(object sender, CreatingEditGroupsEventArgs e)
        {
            try
            {

                // Go through each column in the feature being edited
                FeatureDataRow fdr = e.FeatureDataRow;

                // Set the feature data row to a new value
                foreach (DataColumn dc in fdr.FeatureLayer.Columns)
                {
                    // Auto Populate the DATE Field when a new feature is collected
                    if (dc.ColumnName.ToLower().IndexOf("date") != -1)
                    {
                        fdr[dc.ColumnName] = DateTime.Now;
                    }
                }

                // Now, set the default text value of the group to the same as above
                // This is done because a simple "refresh()" cannot be called (it doesn't work)
                for (int i = 0; i < e.Groups.Count; i++)
                {
                    // Assume that there are two TextItems within each group by default
                    // Check for this:
                    if (e.Groups.Items.Count == 2)
                    {
                        // Check that the first and second Item are of type TextItem
                        if (e.Groups.Items[0].GetType() == typeof(TextItem) && e.Groups.Items[1].GetType() == typeof(TextItem))
                        {
                            // The item is now assumed a TextItem, so now cast it:
                            TextItem itemHeader = (TextItem)e.Groups.Items[0];

                            // Check that the text value contains "date"
                            if (itemHeader.Text.ToLower().IndexOf("date") != -1)
                            {
                                // Code to "refresh" the date attribute:
                                // this is the date column, now auto populate it with today's date
                                TextItem dateItem = (TextItem)e.Groups.Items[1];
                                dateItem.Text = DateTime.Now.ToString();
                                
                                // Code to simply hide it only ever allowing the auto populate code to
                                // add the information in:
                                e.Groups.Items.Clear();
                            }
                        }
                    }

                }
            }
            catch (Exception ex)
            {
                ESRI.ArcGIS.Mobile.Client.Dialogs.MessageDialog.Show(ex.Message, "ERROR Edit Attributes", MessageBoxButtons.OK);
            }   
        }




I don't see any problems with doing the solution above, the if statements are pretty solid, as long as you're checking for right types we should be good to go. I love that you can auto populate it and hide it. Users are complaining that if they are auto populated, they might as well not even see it in the edit form. So items.clear() takes care of that nicely!

Woo!

-Jon
0 Kudos
AkhilParujanwala
Regular Contributor
Nice work! Code looks great. I may have to implement this for one of my fields.

Thanks!
0 Kudos
KierenTinning1
Deactivated User
Nice coding on these tools.

I accomplished the same by pre-populated all the fields on the feature (created new) then called the Edit Attributes Dialog after and passing in the feature.

Question for you both, do you know how to get a handle on a particular group? I.e. if I click on the 'PartNumber' field (group), how do I raise a custom data entry page?

Thanks,

E
0 Kudos