Exemplo n.º 1
0
        private void mapControl1_GeometrySelected(object sender, SuperMap.UI.GeometrySelectedEventArgs e)
        {
            //获取选择集
            Selection[] selection = mapControl1.Map.FindSelection(true);

            //判断选择集是否为空
            if (selection == null || selection.Length == 0)
            {
                MessageBox.Show("请选择要查询属性的空间对象");
                return;
            }

            //将选择集转换为记录
            Recordset recordset = selection[0].ToRecordset();

            this.dataGridView1.Columns.Clear();
            this.dataGridView1.Rows.Clear();

            for (int i = 0; i < recordset.FieldCount; i++)
            {
                //定义并获得字段名称
                String fieldName = recordset.GetFieldInfos()[i].Name;

                //将得到的字段名称添加到dataGridView列中
                this.dataGridView1.Columns.Add(fieldName, fieldName);
            }

            //初始化row
            DataGridViewRow row = null;

            //根据选中记录的个数,将选中对象的信息添加到dataGridView中显示
            while (!recordset.IsEOF)
            {
                row = new DataGridViewRow();
                for (int i = 0; i < recordset.FieldCount; i++)
                {
                    //定义并获得字段值
                    Object fieldValue = recordset.GetFieldValue(i);

                    //将字段值添加到dataGridView中对应的位置
                    DataGridViewTextBoxCell cell = new DataGridViewTextBoxCell();
                    if (fieldValue != null)
                    {
                        cell.ValueType = fieldValue.GetType();
                        cell.Value     = fieldValue;
                    }
                    row.Cells.Add(cell);
                }

                this.dataGridView1.Rows.Add(row);

                recordset.MoveNext();
            }
            this.dataGridView1.Update();

            recordset.Dispose();
        }
Exemplo n.º 2
0
 /// <summary>
 /// 对象选择事件
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 private void m_mapControl_GeometrySelected(object sender, SuperMap.UI.GeometrySelectedEventArgs e)
 {
     try
     {
         this.FillDataGridView(m_sampleRun.GetSelectedRecordset(false));
     }
     catch (Exception ex)
     {
         Trace.WriteLine(ex.Message);
     }
 }