public void SetTableSource(IFeatureSet fs, int layerHandle, bool ogr) { if (fs == null) { RowCount = 0; return; } _layerHandle = layerHandle; _shapefile = fs; _table = fs.Table; _ogr = ogr; InitColumns(_table); RowManager.Reset(_shapefile); RowCount = 0; // this will clear all rows at once or else it will try to remove them one by one (veeeery slow) RowCount = _table.NumRows; bool editing = _shapefile.CanEditTable(); ReadOnly = !editing; }
public void ClearSorting() { RowManager.ClearSorting(TableSource); foreach (DataGridViewColumn cmn in Columns) { cmn.HeaderCell.SortGlyphDirection = SortOrder.None; } Invalidate(); }
private void SortByColumn <T>(int cmnIndex, bool ascending) where T : IComparable { var list = new List <SortItem <T> > { Capacity = _table.NumRows }; string defValue = string.Empty; bool isString = typeof(T) == typeof(string); for (int i = 0; i < _table.NumRows; i++) { var val = _table.CellValue(cmnIndex, i); if (val == null) { if (isString) { val = defValue; } else { val = default(T); } } var item = new SortItem <T>((T)val, i); list.Add(item); } list.Sort(); if (!ascending) { list.Reverse(); } var result = list.Select(item => item.RealIndex); RowManager.SetSorting(cmnIndex, ascending, result); }
private void GridCellValueNeeded(object sender, DataGridViewCellValueEventArgs e) { int realIndex = RowManager.RealIndex(e.RowIndex); e.Value = _table.CellValue(e.ColumnIndex, realIndex); }
private void GridCellValuePushed(object sender, DataGridViewCellValueEventArgs e) { var s = e.Value as string; int realIndex = RowManager.RealIndex(e.RowIndex); var fld = _table.Fields[e.ColumnIndex]; if (s == null) { switch (fld.Type) { case AttributeType.String: _table.EditCellValue(e.ColumnIndex, realIndex, string.Empty); break; case AttributeType.Integer: _table.EditCellValue(e.ColumnIndex, realIndex, 0); break; case AttributeType.Double: _table.EditCellValue(e.ColumnIndex, realIndex, 0.0); break; case AttributeType.Boolean: _table.EditCellValue(e.ColumnIndex, realIndex, false); break; case AttributeType.Date: _table.EditCellValue(e.ColumnIndex, realIndex, DateTime.MinValue); break; } } else { switch (fld.Type) { case AttributeType.String: if (fld.Width < s.Length) { MessageService.Current.Info("The string is too long and will be truncated."); s = s.Substring(0, fld.Width); } _table.EditCellValue(e.ColumnIndex, realIndex, s); break; case AttributeType.Integer: { if (int.TryParse(s, out int val)) { _table.EditCellValue(e.ColumnIndex, realIndex, val); } else { MessageService.Current.Info("The string is not recognized as an integer value."); } } break; case AttributeType.Double: { if (double.TryParse(s, out double val)) { _table.EditCellValue(e.ColumnIndex, realIndex, val); } else { MessageService.Current.Info( "The string is not recognized as a floating point numeric value."); } } break; case AttributeType.Date: { if (DateTime.TryParse(s, out DateTime val)) { _table.EditCellValue(e.ColumnIndex, realIndex, val); } else { MessageService.Current.Info( "The string is not recognized as a date/time value."); } } break; case AttributeType.Boolean: { if (bool.TryParse(s, out bool val)) { _table.EditCellValue(e.ColumnIndex, realIndex, val); } else { MessageService.Current.Info( "The string is not recognized as a boolean value."); } } break; } } DelegateHelper.FireEvent(this, CellValueEdited); }