//查询要素 private void btnSearch_Click(object sender, EventArgs e) { //查询图层对应的要素 sLayer.QuerySQL(tbxSQL.Text, SelectedMode.New); //查询的模式,更新结果 SelectionIsImput = true; RefreshSelectFeature(); SelectionIsImput = false; //触发联动事件,form1显示选择要素 SelectFeatureChanged?.Invoke(this); }
//选择要素改变 private void dataGridView1_SelectionChanged(object sender, EventArgs e) { if (!SelectionIsImput) { //清除之前的要素 sLayer.SelectedItems.Clear(); if (dataGridView1.SelectedRows.Count > 0) { //遍历,找到选择的要素 foreach (DataGridViewRow row in dataGridView1.SelectedRows) { if (row.Cells["ID"].Value != null) //ID不为空 { int ID = (int)row.Cells["ID"].Value; sLayer.SelectedItems.Add(ID); } } } } //联动,form1显示选择的要素 SelectFeatureChanged?.Invoke(this); }