高亮显示在属性表中选中的要素

高亮显示在属性表中选中的要素  

/// <summary>
/// 高亮显示在属性表中选中的要素
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void dataGridView1_RowHeaderMouseClick(object sender, DataGridViewCellMouseEventArgs e)
{
    frmMap.m_mapCtrl.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGeoSelection, null, null);
    IQueryFilter pQuery = new QueryFilterClass();
    int count = this.dataGridView1.SelectedRows.Count;
    string val;
    string col;
    col = this.dataGridView1.Columns[0].Name;
    //当只选中一行时
    if(count==1)
    {
        val = this.dataGridView1.SelectedRows[0].Cells[col].Value.ToString();
        //设置高亮要素的查询条件
        pQuery.WhereClause = col + "=" + val;
    }
    else//当选中多行时
    {
        int i;
        string str;
        for (i = 0; i < count-1; i++)
        {
            val = this.dataGridView1.SelectedRows[i].Cells[col].Value.ToString();
            str = col + "=" + val + " OR ";
            pQuery.WhereClause += str;
        }
        //添加最后一个要素的条件
        val = this.dataGridView1.SelectedRows[i].Cells[col].Value.ToString();
        str = col + "=" + val;
        pQuery.WhereClause += str;
    }
    IFeatureLayer pFeatureLayer = layer as IFeatureLayer;
    IFeatureSelection pFeatSelection;
    pFeatSelection = pFeatureLayer as IFeatureSelection;
    pFeatSelection.SelectFeatures(pQuery, esriSelectionResultEnum.esriSelectionResultNew,false);
    frmMap.m_mapCtrl.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGeoSelection, null, null);                                  
}
posted @ 2012-06-21 16:49  lockener  阅读(411)  评论(0编辑  收藏  举报