木白林
路人甲
路人甲
  • 注册日期2004-03-19
  • 发帖数319
  • QQ
  • 铜币824枚
  • 威望0点
  • 贡献值0点
  • 银元0个
阅读:2468回复:6

AE中将某个字段赋给combobox,请指教

楼主#
更多 发布于:2005-08-15 10:16
<P>下面是原来VBA中的代码:其中g_xzqht是窗体名,g_zm是combobox,我想实现的就是能在combobox的下拉中找到dbf中“镇名”的所有属性值。</P>
<P>Private Sub UserForm_Initialize()</P>
<P> ' (1) Access the State layer</P>
<P>On Error GoTo Error_h<BR>  <BR>  Dim player As IFeatureLayer<BR>  Dim pFeatureClass As IFeatureClass<BR>  Dim c_strDataPath As String<BR>  c_strDataPath = Allpath<BR>  <BR>  Const c_strStateLayerName = "乡镇区划图"<BR>  Set player = g_public.GetLayer(c_strStateLayerName)<BR> <BR> <BR>  Set pFeatureClass = player.FeatureClass<BR>  <BR>  ' (2) Sort State layer's table<BR>  Dim pTableSort As ITableSort<BR>  Set pTableSort = New TableSort<BR>  pTableSort.Fields = "镇名"<BR>  pTableSort.Ascending("镇名") = False<BR>  Set pTableSort.Table = pFeatureClass<BR>  pTableSort.Sort Nothing<BR>  <BR>  ' (3) Populate the State's combo box<BR>  Dim pCursor As ICursor<BR>  Dim pRow As IRow<BR>  Dim lngFieldIndex As Long<BR>  'Set pCursor = pTableSort.Rows<BR>  Set pCursor = pTableSort.Rows<BR>  <BR>  lngFieldIndex = pFeatureClass.FindField("镇名")<BR>  Set pRow = pCursor.NextRow<BR>  Do While Not pRow Is Nothing<BR>   ' cboState.AddItem pRow.Value(lngFieldIndex)<BR>   g_xzqht.g_zm.AddItem pRow.Value(lngFieldIndex)<BR>   <BR>    Set pRow = pCursor.NextRow<BR>  Loop<BR>  g_xzqht.g_zm.ListIndex = 0</P>
<P><BR>Error_h:<BR>End Sub</P>

<P>Public Function GetLayer(strLayerName As String) As _<BR>IFeatureLayer<BR>  ' This function accepts a layer name and returns<BR>  ' the layer if available, otherwise returns "Nothing".<BR>  ' (1) Access the document's map<BR>Dim pMxDoc As IMxDocument<BR>Dim pMap As IMap<BR>Set pMxDoc = Application.Document<BR>Set pMap = pMxDoc.FocusMap<BR>' (2) Search through layers for the given layer name<BR>Dim lngIndex As Long<BR>Set GetLayer = Nothing<BR>For lngIndex = 0 To pMap.LayerCount - 1<BR>  If pMap.Layer(lngIndex).name = strLayerName Then<BR>    Set GetLayer = pMap.Layer(lngIndex)<BR>    Exit For<BR>  End If<BR>Next lngIndex<BR>End Function</P>
<P>下面是我在AE中改后的,没有报错,但是实现不了,给我的感觉好象是没有和层的dbf关联起来</P>
<P>Private Sub Form_Load()<BR> ' Access the State layer</P>
<P><BR>  On Error GoTo Error_h<BR>  Dim m_pMapControl As IMapControl3<BR>  Dim player As ILayer<BR>  Set player = m_pMapControl.CustomProperty<BR>  Dim pfeacls As IFeatureClass<BR>  Dim pFeatureLayer As IFeatureLayer<BR>  <BR>    Set pFeatureLayer = player<BR>    Set pfeacls = pFeatureLayer.FeatureClass<BR>    'Set pfields = pfeacls.Fields<BR>  <BR>  ' Sort State layer's table<BR>  Dim pTableSort As ITableSort<BR>  Set pTableSort = New TableSort<BR>  pTableSort.Fields = "镇名"<BR>  pTableSort.Ascending("镇名") = False<BR>  Set pTableSort.table = pfeacls<BR>  pTableSort.Sort Nothing<BR>  <BR>  '<BR>  ' Populate the State's combo box<BR>  Dim pCursor As ICursor<BR>  Dim pRow As IRow<BR>  Dim lngFieldIndex As Long<BR>  'Set pCursor = pTableSort.Rows<BR>  Set pCursor = pTableSort.Rows<BR>  <BR>  lngFieldIndex = pfeacls.FindField("镇名")<BR>  Set pRow = pCursor.NextRow<BR>  Do While Not pRow Is Nothing<BR>   ' cboState.AddItem pRow.Value(lngFieldIndex)<BR>   g_xzqht.g_zm.AddItem pRow.Value(lngFieldIndex)<BR>   <BR>    Set pRow = pCursor.NextRow<BR>  Loop<BR>  g_xzqht.g_zm.ListIndex = 0</P>
<P>'End Sub<BR>Error_h:<BR> <BR>End Sub </P>
<img src="images/post/smile/dvbbs/em12.gif" />
喜欢0 评分0
心情卡片 一起分享...
木白林
路人甲
路人甲
  • 注册日期2004-03-19
  • 发帖数319
  • QQ
  • 铜币824枚
  • 威望0点
  • 贡献值0点
  • 银元0个
1楼#
发布于:2005-08-16 10:47
搞定了,谢谢大家!谢谢GIS
心情卡片 一起分享...
举报 回复(0) 喜欢(0)     评分
gis
gis
管理员
管理员
  • 注册日期2003-07-16
  • 发帖数15951
  • QQ
  • 铜币25345枚
  • 威望15368点
  • 贡献值0点
  • 银元0个
  • GIS帝国居民
  • 帝国沙发管家
  • GIS帝国明星
  • GIS帝国铁杆
2楼#
发布于:2005-08-16 09:51
<P>用layercount循环</P>

<P>读取加载到mapcontrol的层就可以了啊</P>
GIS麦田守望者,期待与您交流。
举报 回复(0) 喜欢(0)     评分
木白林
路人甲
路人甲
  • 注册日期2004-03-19
  • 发帖数319
  • QQ
  • 铜币824枚
  • 威望0点
  • 贡献值0点
  • 银元0个
3楼#
发布于:2005-08-15 23:20
<P>就是如何在我新建的一个窗体中取得加载到mapcontrol的层,</P>
<P>Const c_strStateLayerName = "乡镇区划图"<BR>  Set player = g_public.GetLayer(c_strStateLayerName)<BR><BR><BR>  Set pFeatureClass = player.FeatureClass<BR></P>
心情卡片 一起分享...
举报 回复(0) 喜欢(0)     评分
wavvylia
路人甲
路人甲
  • 注册日期2003-07-28
  • 发帖数384
  • QQ
  • 铜币555枚
  • 威望0点
  • 贡献值0点
  • 银元0个
4楼#
发布于:2005-08-15 15:55
<P>太长,最好你直接描述你的问题!</P>
举报 回复(0) 喜欢(0)     评分
木白林
路人甲
路人甲
  • 注册日期2004-03-19
  • 发帖数319
  • QQ
  • 铜币824枚
  • 威望0点
  • 贡献值0点
  • 银元0个
5楼#
发布于:2005-08-15 12:11
现在的问题就是取得层,这一步实现了,其他的都不用说了
心情卡片 一起分享...
举报 回复(0) 喜欢(0)     评分
flycui83
路人甲
路人甲
  • 注册日期2005-03-18
  • 发帖数46
  • QQ
  • 铜币247枚
  • 威望0点
  • 贡献值0点
  • 银元0个
6楼#
发布于:2005-08-15 11:53
你直接读图层嘛 加进去就完了啊
举报 回复(0) 喜欢(0)     评分
游客

返回顶部