private void fieldvaluelistBox_DoubleClick(object sender, EventArgs e) { if (m_FieldName != null && m_FieldName != "") { bool isExit = false; string tempCode = fieldvaluelistBox.SelectedItem.ToString(); if (tempCode.Contains("'")) { isExit = true; tempCode = tempCode.Substring(1, tempCode.LastIndexOf("'") - 1); } string fieldCode = ModXZQ.GetCode(m_pWorkspace, m_FieldName, tempCode); if (isExit) { sqlrichTextBox.Text = sqlrichTextBox.Text + "'" + fieldCode + "'"; } else { sqlrichTextBox.Text = sqlrichTextBox.Text + fieldCode; } } else { sqlrichTextBox.Text = sqlrichTextBox.Text + fieldvaluelistBox.SelectedItem.ToString() + " "; } }
private void guvbuttonX_Click(object sender, EventArgs e) { fieldvaluelistBox.Items.Clear(); m_FieldName = ""; string strfieldName = fieldlistBox.SelectedItem.ToString(); strfieldName = strfieldName.Substring(0, strfieldName.IndexOf('【')); m_FieldName = strfieldName; bool blnStr = false; if (m_pFeaCls.Fields.get_Field(m_pFeaCls.Fields.FindField(strfieldName)).Type == esriFieldType.esriFieldTypeString) { blnStr = true; } if (m_pFeaCls == null || this.fieldlistBox.SelectedItems.Count == 0) { return; } string sFieldName = strfieldName; //获取选中项的字符串 IFeatureClass pFeatureClass = m_pFeaCls; //得到要素集合 if (pFeatureClass == null) { return; } this.fieldvaluelistBox.Items.Clear(); try { IFeatureCursor pCursor = null; if (m_Geometry == null) { IQueryFilter pQueryFilter = new QueryFilterClass(); pQueryFilter.WhereClause = ""; pCursor = pFeatureClass.Search(pQueryFilter, false); } else { ISpatialFilter pSpatialFilter = new SpatialFilterClass(); //pSpatialFilter.GeometryField = "SHAPE"; pSpatialFilter.Geometry = m_Geometry; pSpatialFilter.SpatialRel = esriSpatialRelEnum.esriSpatialRelIntersects; pSpatialFilter.WhereClause = ""; pCursor = pFeatureClass.Search(pSpatialFilter, false); } List <string> listFieldValue = ModXZQ.GetListChineseName(m_pWorkspace, strfieldName); if (listFieldValue != null || listFieldValue.Count != 0) { for (int t = 0; t < listFieldValue.Count; t++) { if (blnStr) { fieldvaluelistBox.Items.Add("'" + listFieldValue [t] + "'"); } else { fieldvaluelistBox.Items.Add(listFieldValue[t]); } } fieldvaluelistBox.Update(); } else { System.Collections.IEnumerator enumerator; IDataStatistics DS = new DataStatisticsClass(); DS.Field = sFieldName; //设置唯一值字段 DS.Cursor = pCursor as ICursor; //数据来源 enumerator = DS.UniqueValues; //得到唯一值 enumerator.Reset(); //从新指向第一个值 while (enumerator.MoveNext()) //遍历唯一值 { string strTemp = enumerator.Current.ToString(); if (blnStr) { fieldvaluelistBox.Items.Add("'" + strTemp + "'"); } else { fieldvaluelistBox.Items.Add(strTemp); } } System.Runtime.InteropServices.Marshal.ReleaseComObject(pCursor); pCursor = null; //lstValue.Sorted=true; fieldvaluelistBox.Update(); } } catch (Exception ex) { MessageBox.Show("获取字段值发生错误,错误原因为" + ex.Message, "系统提示"); } }