Select to view content in your preferred language

Initialize FeatureDataGrid in VB not C#

453
0
02-08-2012 03:31 AM
KenCarrier
Regular Contributor
All,

I am trying to initialize a FeatureDataGrid in Silverlight using VB.

Esri has been kind enough to share some C# code with me but when I try to convert to VB, it does not convert cleanly. My code will not work properly until I get the FDG initialized properly.

Any help would be greatly appreciated.

Original Code in C#
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using ESRI.ArcGIS.Client;
using ESRI.ArcGIS.Client.Tasks;
using ESRI.ArcGIS.Client.Geometry;

namespace ForumTest
{
 public partial class MainPage : UserControl
 {
  public MainPage()
  {
   InitializeComponent();
   l = new FeatureLayer()
   {
    ID = "MyLayer",
    Url = "http://sampleserver3.arcgisonline.com/ArcGIS/rest/services/SanFrancisco/311Incidents/FeatureServer/1",
    Mode = FeatureLayer.QueryMode.Snapshot,
    Where = "1=1"
   };
   l.OutFields.Add("*");
   l.Initialized += (s, e) => 
   {
    if (l.InitializationFailure != null)
     MessageBox.Show(l.InitializationFailure.Message);
   };
   l.InitializationFailed += (s, e) =>
   {
    if (l.InitializationFailure != null)
     MessageBox.Show(l.InitializationFailure.Message);
   };
   l.Initialized += new EventHandler<EventArgs>(l_Initialized);
   l.Initialize();  
   MyFDG.GraphicsLayer = l;  
  }

  void l_Initialized(object sender, EventArgs e)
  {
   var l = sender as FeatureLayer;
   l.Update();
  }
  FeatureLayer l;

  private void Button_Click(object sender, RoutedEventArgs e)
  {
   var g = new Graphic();
   if (l != null && l.LayerInfo != null && l.LayerInfo.Fields != null)
   {
    foreach (var f in l.LayerInfo.Fields)
    {
     g.Attributes[f.Name] = null;
    }
   }
   else
   {
    g.Attributes["sf_311_serviceoid"] = 21467;
    g.Attributes["agree_with_incident"] = (Int16)1;
    g.Attributes["DateTime"] = DateTime.UtcNow;
    g.Attributes["cient_ip"] = "unknown";
    g.Attributes["notes"] = string.Format("Added - {0} - local time", DateTime.Now);
   }
   l.Graphics.Add(g);
  }
 }
}



Converted to VB:
Imports System.Collections.Generic
Imports System.Linq
Imports System.Net
Imports System.Windows
Imports System.Windows.Controls
Imports System.Windows.Documents
Imports System.Windows.Input
Imports System.Windows.Media
Imports System.Windows.Media.Animation
Imports System.Windows.Shapes
Imports ESRI.ArcGIS.Client
Imports ESRI.ArcGIS.Client.Tasks
Imports ESRI.ArcGIS.Client.Geometry

Namespace ForumTest
 Public Partial Class MainPage
  Inherits UserControl
  Public Sub New()
   InitializeComponent()
   l = New FeatureLayer() With { _
    Key .ID = "MyLayer", _
    Key .Url = "http://sampleserver3.arcgisonline.com/ArcGIS/rest/services/SanFrancisco/311Incidents/FeatureServer/1", _
    Key .Mode = FeatureLayer.QueryMode.Snapshot, _
    Key .Where = "1=1" _
   }
   l.OutFields.Add("*")
   l.Initialized += Function(s, e) 
   If l.InitializationFailure IsNot Nothing Then
    MessageBox.Show(l.InitializationFailure.Message)
   End If

End Function
   l.InitializationFailed += Function(s, e) 
   If l.InitializationFailure IsNot Nothing Then
    MessageBox.Show(l.InitializationFailure.Message)
   End If

End Function
   l.Initialized += New EventHandler(Of EventArgs)(AddressOf l_Initialized)
   l.Initialize()
   MyFDG.GraphicsLayer = l
  End Sub

  Private Sub l_Initialized(sender As Object, e As EventArgs)
   Dim l = TryCast(sender, FeatureLayer)
   l.Update()
  End Sub
  Private l As FeatureLayer

  Private Sub Button_Click(sender As Object, e As RoutedEventArgs)
   Dim g = New Graphic()
   If l IsNot Nothing AndAlso l.LayerInfo IsNot Nothing AndAlso l.LayerInfo.Fields IsNot Nothing Then
    For Each f As var In l.LayerInfo.Fields
     g.Attributes(f.Name) = Nothing
    Next
   Else
    g.Attributes("sf_311_serviceoid") = 21467
    g.Attributes("agree_with_incident") = CType(1, Int16)
    g.Attributes("DateTime") = DateTime.UtcNow
    g.Attributes("cient_ip") = "unknown"
    g.Attributes("notes") = String.Format("Added - {0} - local time", DateTime.Now)
   End If
   l.Graphics.Add(g)
  End Sub
 End Class
End Namespace
0 Kudos
0 Replies