void OnPointerReleased(object sender, PointerRoutedEventArgs e) { if (e.IsTouch()) { // 触摸模式只支持列排序 if (_pointerID == e.Pointer.PointerId) { ReleasePointerCapture(e.Pointer); _pointerID = null; ChangedSortState(); } return; } if (_isDragging) { if (_dragTgtCol != null) { // 拖拽结束 _owner.FinishedDrag(); Cols cols = _owner.Lv.Cols; int index = cols.IndexOf(_dragTgtCol); cols.Remove(Col); cols.Insert(index, Col); cols.Invalidate(); } else { // 列排序 ChangedSortState(); } } ResetMouseState(); }
/// <summary> /// Creates a col. /// </summary> /// <param name="selc"></param> /// <seealso cref="CreateCols()"><c>CreateCols()</c></seealso> internal void CreateCol(int selc) { --selc; // the Field-count is 1 less than the col-count int fieldsLength = Fields.Length + 1; // create a new Fields array -> var fields = new string[fieldsLength]; for (int i = 0; i != fieldsLength; ++i) { if (i < selc) { fields[i] = Fields[i]; } else if (i == selc) { fields[i] = InputDialog._colabel; var col = new Col(); col.text = InputDialog._colabel; col._widthtext = YataGraphics.MeasureWidth(col.text, _f.FontAccent); col.width(col._widthtext + _padHori * 2 + _padHoriSort); col.selected = true; Cols.Insert(i + 1, col); ++ColCount; for (int r = 0; r != RowCount; ++r) { var cells = new Cell[ColCount]; // create a new Cells array in each row -> for (int c = 0; c != ColCount; ++c) { if (c < selc + 1) { cells[c] = this[r, c]; } else if (c == selc + 1) { cells[c] = new Cell(r, c, gs.Stars); cells[c].selected = true; cells[c]._widthtext = _wStars; } else // (c > selc + 1) { cells[c] = this[r, c - 1]; cells[c].x += 1; } } Rows[r]._cells = cells; Rows[r].Length += 1; } } else // (i > selc) { fields[i] = Fields[i - 1]; } } Fields = fields; int w = _wStars + _padHori * 2; if (w > Cols[++selc].width()) { Cols[selc].width(w); } InitScroll(); EnsureDisplayedCol(selc); _f.EnableCelleditOperations(); if (!Changed) { Changed = true; } }
protected override void RefreshView() { bool needFill = Rows.Count > 0; var oldTable = _table; _currentFields = _fields.GetFieldsForView(); // fill DataTable to use as DataSource DataTable table = new DataTable(); foreach (var field in _currentFields.Values) { var c = table.Columns.Add(field.Name, field.DataType); c.Caption = field.Caption; } // Id is primary key var col = table.Columns["Id"]; col.Unique = true; table.PrimaryKey = new DataColumn[] { col }; table.RowChanged += Table_RowChanged; table.RowDeleting += Table_RowDeleting; _table = table; this.DataSource = table; // cleanup old table if (oldTable != null) { oldTable.RowChanged -= Table_RowChanged; oldTable.RowDeleting -= Table_RowDeleting; oldTable.Clear(); } // more settings for autogenerated FlexGrid columns foreach (Column flexCol in Cols) { var field = _currentFields[flexCol.Name]; flexCol.Visible = field.Visible; flexCol.AllowEditing = !field.ReadOnly; if (flexCol.DataType == typeof(DateTime)) { // allow showing and editing time part flexCol.Format = "g"; } if (flexCol.Name == "Icon") { flexCol.ImageAndText = false; flexCol.ImageMap = Icons; // set dictionary with images flexCol.AllowFiltering = C1FlexGrid.AllowFiltering.None; flexCol.Width = Rows[0].HeightDisplay; } if (flexCol.Name == "Subject") { flexCol.StarWidth = "*"; } if (flexCol.Name == "Start") { flexCol.Sort = SortFlags.Ascending; } } // set grouping based on fields GroupDescriptions = null; Dictionary <int, AppointmentField> fieldsForGrouping = new Dictionary <int, AppointmentField>(); foreach (var f in _currentFields.Values) { if (f.GroupIndex >= 0) { fieldsForGrouping.Add(f.GroupIndex, f); } } // add fields which only need sort to the end of collection foreach (var f in _currentFields.Values) { if (f.GroupIndex == -1 && f.Sort != SortFlags.None) { fieldsForGrouping.Add(fieldsForGrouping.Count, f); } } var groups = new List <GroupDescription>(); // loop by index to add groups in correct order for (int i = 0; i < fieldsForGrouping.Count; i++) { if (fieldsForGrouping.ContainsKey(i)) { var field = fieldsForGrouping[i]; Column groupCol = Cols[field.Name]; groups.Add(new GroupDescription( field.Name, field.Sort == SortFlags.Ascending ? ListSortDirection.Ascending : ListSortDirection.Descending, field.GroupIndex >= 0)); } } if (groups.Count > 0) { GroupDescriptions = groups; // insert unbound column for grouping var column = Cols.Insert(0); column.TextAlign = TextAlignEnum.LeftCenter; // column.Visible = false; column.Width = 1; } if (_fields.ContainsKey("RecurrencePattern") && _fields["RecurrencePattern"].GroupIndex == -1) { this.AutoSizeCol(Cols["RecurrencePattern"].Index, 50); } this.Sort(SortFlags.UseColSort, 0, Cols.Count - 1); if (needFill) { OnAppointmentsLoaded(); } }