/// <summary> /// handle data grid view selection change /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void DataGridView1SelectionChanged(object sender, EventArgs e) { if (!_featureLayer.DataSet.AttributesPopulated) { return; // For now can handle only populated data sets with fid column } Debug.Assert(_fidField != null); if (_ignoreTableSelectionChanged) { return; } _ignoreSelectionChanged = true; try { //manage selection using the Selection property IndexSelection sel = _featureLayer.Selection as IndexSelection; if (sel != null) { sel.SuspendChanges(); //set the selected state of the corresponding feature foreach (DataGridViewRow row in dataGridView1.Rows) { int fid = (int)row.Cells[_fidField].Value; if (row.Selected) { sel.Add(fid); } else { sel.Remove(fid); } } sel.ResumeChanges(); } else { List <int> adds = new List <int>(); List <int> removes = _selectedRows.ToList(); foreach (DataGridViewRow row in dataGridView1.SelectedRows) { if (!_selectedRows.Contains(row.Index)) { adds.Add(row.Index); } removes.Remove(row.Index); } _featureLayer.Select(adds); _featureLayer.UnSelect(removes); } } finally { _ignoreSelectionChanged = false; } }
public void GetAttributes_WithFieldNames() { var fs = new FeatureSet(FeatureType.Point); fs.DataTable.Columns.Add("Column1"); fs.DataTable.Columns.Add("Column2"); fs.AddFeature(new Point(0, 0)); var fl = new PointLayer(fs); var target = new IndexSelection(fl); var attributesTable = target.GetAttributes(0, 1, new[] {"Column1"}); Assert.AreEqual(1, attributesTable.Columns.Count); Assert.AreEqual("Column1", attributesTable.Columns[0].ColumnName); }
public void GetAttributes_WithFieldNames() { var fs = new FeatureSet(FeatureType.Point); fs.DataTable.Columns.Add("Column1"); fs.DataTable.Columns.Add("Column2"); fs.AddFeature(new Point(0, 0)); var fl = new PointLayer(fs); var target = new IndexSelection(fl); var attributesTable = target.GetAttributes(0, 1, new[] { "Column1" }); Assert.AreEqual(1, attributesTable.Columns.Count); Assert.AreEqual("Column1", attributesTable.Columns[0].ColumnName); }