// クラスを作らない方法 private ILayer[] layers = null; private void Form1_Load(object sender, EventArgs e) { AxMapControl map = (AxMapControl)m_Main.Controls["axMapControl1"]; layers = new ILayer[map.LayerCount]; for (int i = 0; i < map.LayerCount; i++) { layers[i] = map.get_Layer(i); } comboBox1.DataSource = layers; comboBox1.DisplayMember = "Name"; } private void comboBox1_SelectionChangeCommitted(object sender, EventArgs e) { IFeatureLayer fl = comboBox1.SelectedValue as IFeatureLayer; : : }
Private layers As ILayer() = Nothing Private Sub Form1_Load(ByVal sender As Object, ByVal e As EventArgs) Dim map As AxMapControl = DirectCast(m_Main.Controls("axMapControl1"), AxMapontrol) layers = New ILayer(map.LayerCount - 1) {} For i As Integer = 0 To map.LayerCount - 1 layers(i) = map.get_Layer(i) Next comboBox1.DataSource = layers comboBox1.DisplayMember = "Name" End Sub Private Sub comboBox1_SelectionChangeCommitted(ByVal sender As Object, ByVal e A EventArgs) Dim fl As IFeatureLayer = TryCast(comboBox1.SelectedValue, IFeatureLayer) End Sub Private Sub ComboBox1_SelectedIndexChanged(ByVal sender As System.Object, ByVa e System.EventArgs) Handles ComboBox1.SelectedIndexChanged Dim pLayer As ILayer pLayer = CType(ComboBox1.SelectedItem, ComboLayer).Layer MessageBox.Show(pLayer.Name) End Sub Private Sub subAddLayerList() ComboBox1.Items.Clear() Dim pEnumLayer As IEnumLayer pEnumLayer = axMapControl1.Map.Layers(, True) Dim pLayer As ILayer pEnumLayer.Reset() pLayer = pEnumLayer.Next Dim pArrLayer As ComboLayer Dim pArrayList As New ArrayList() Do Until pLayer Is Nothing pArrLayer = New ComboLayer pArrLayer.Layer = pLayer pArrayList.Add(CType(pArrLayer, ComboLayer)) 'ComboBox1.Items.Add(CType(pLayer, Object)) pLayer = pEnumLayer.Next Loop 'ComboBoxにArrayListを追加して該当の名称を指定 ComboBox1.DataSource = pArrayList ComboBox1.ValueMember = "Layer" ComboBox1.DisplayMember = "Name" End Sub 'ComboBoxにレイヤリストを追加するための独自クラス '参考:http://www.bnote.net/vb/relate_combobox.shtml Private Class ComboLayer Protected m_strName As String Protected m_pLayer As ILayer Public Sub New() End Sub Public ReadOnly Property Name() As String Get Return m_pLayer.Name End Get 'Set(ByVal value As String) ' m_strLayerName = value 'End Set End Property Public Property Layer() As ILayer Get Return m_pLayer End Get Set(ByVal value As ILayer) m_pLayer = value End Set End Property Public Overrides Function ToString() As String Return Me.Name End Function End Class