private void SimulateComboBox(List <object> list, CellBeforeEditEventArgs e) { int currentColIndex = e.Cell.Column; int currentRowIndex = e.Cell.Row; Window window = new Window(); WrapPanel wrapPanel = new WrapPanel(); ListBox listBox = new ListBox(); listBox.SetValue(ScrollViewer.HorizontalScrollBarVisibilityProperty, ScrollBarVisibility.Hidden); listBox.SetValue(ScrollViewer.VerticalScrollBarVisibilityProperty, ScrollBarVisibility.Hidden); listBox.Width = _ColumnWidthList.ElementAt(e.Cell.Column); for (int i = 0; i < list.Count; i++) { var item = list.ElementAt(i); ListBoxItem listBoxItem = new ListBoxItem(); listBoxItem.Content = item; listBox.Items.Add(listBoxItem); } listBox.RenderTransform = new ScaleTransform(_Worksheet.ScaleFactor, _Worksheet.ScaleFactor); listBox.MouseDoubleClick += (object obj, MouseButtonEventArgs eventArgs) => { e.EditText = (listBox.SelectedValue as ListBoxItem).Content.ToString(); window.DialogResult = true; }; wrapPanel.Children.Add(listBox); Point point = new Point(); for (int rowIndex = 0; rowIndex <= currentRowIndex + 1; rowIndex++) { point.Y += (int)(_RowHeightList.ElementAt(rowIndex) * _Worksheet.ScaleFactor); } for (int colIndex = 0; colIndex < currentColIndex; colIndex++) { point.X += (int)(_ColumnWidthList.ElementAt(colIndex) * _Worksheet.ScaleFactor); } point.X += (int)(_Worksheet.RowHeaderWidth * _Worksheet.ScaleFactor); Point screenPoint = _ReoGridControl.PointToScreen(point); window.Width = _Worksheet.ColumnHeaders[e.Cell.Column].Width; window.WindowStyle = WindowStyle.None; window.ResizeMode = ResizeMode.NoResize; window.BorderThickness = new Thickness(0); window.Content = wrapPanel; window.SizeToContent = SizeToContent.WidthAndHeight; window.WindowStartupLocation = WindowStartupLocation.Manual; window.Left = screenPoint.X; window.Top = screenPoint.Y; window.Loaded += (object win, RoutedEventArgs routedEventArgs) => { wrapPanel.Width = listBox.RenderSize.Width * _Worksheet.ScaleFactor; wrapPanel.Height = listBox.RenderSize.Height * _Worksheet.ScaleFactor; }; window.ShowDialog(); }
internal bool StartEdit(Cell cell, string newText) { // abort if either spreadsheet or cell is readonly if (this.HasSettings(WorksheetSettings.Edit_Readonly) || cell == null || cell.IsReadOnly) { return(false); } if (this.focusPos != cell.Position) { this.FocusPos = cell.Position; } else { this.ScrollToCell(cell); } string editText = null; if (newText == null) { if (!string.IsNullOrEmpty(cell.InnerFormula)) { editText = "=" + cell.InnerFormula; } else if (cell.InnerData is string) { editText = (string)cell.InnerData; } #if DRAWING && RICHTEXT else if (cell.InnerData is Drawing.RichText) { editText = ((Drawing.RichText)cell.InnerData).ToString(); } #endif // DRAWING && RICHTEXT else { editText = Convert.ToString(cell.InnerData); } this.backupData = editText; } else { editText = newText; this.backupData = cell.DisplayText; } if (cell.DataFormat == CellDataFormatFlag.Percent && this.HasSettings(WorksheetSettings.Edit_FriendlyPercentInput)) { double val; if (double.TryParse(editText, out val)) { editText = (newText == null ? (val * 100) : val) + "%"; } } if (BeforeCellEdit != null) { CellBeforeEditEventArgs arg = new CellBeforeEditEventArgs(cell) { EditText = editText, }; BeforeCellEdit(this, arg); if (arg.IsCancelled) { return(false); } editText = arg.EditText; } #if EX_SCRIPT // v0.8.2: 'beforeCellEdit' renamed to 'onCellEdit' // v0.8.5: 'onCellEdit' renamed to 'oncelledit' object scriptReturn = RaiseScriptEvent("oncelledit", new RSCellObject(this, cell.InternalPos, cell)); if (scriptReturn != null && !ScriptRunningMachine.GetBoolValue(scriptReturn)) { return(false); } #endif if (cell.body != null) { bool canContinue = cell.body.OnStartEdit(); if (!canContinue) { return(false); } } if (currentEditingCell != null) { EndEdit(this.controlAdapter.GetEditControlText()); } this.currentEditingCell = cell; this.controlAdapter.SetEditControlText(editText); if (cell.DataFormat == CellDataFormatFlag.Percent && editText.EndsWith("%")) { this.controlAdapter.SetEditControlCaretPos(editText.Length - 1); } RGFloat x = 0; RGFloat width = (cell.Width - 1) * this.renderScaleFactor; int cellIndentSize = 0; //if ((cell.InnerStyle.Flag & PlainStyleFlag.Indent) == PlainStyleFlag.Indent) //{ //indentSize = (int)Math.Round(cell.InnerStyle.Indent * this.indentSize * this.scaleFactor); //width -= indentSize; //} #if WINFORM if (width < cell.TextBounds.Width) { width = cell.TextBounds.Width; } #elif WPF // why + 6 ? if (width < cell.TextBounds.Width) { width = cell.TextBounds.Width + 6; } #endif width--; //width = (width - 1); RGFloat scale = this.renderScaleFactor; #region Horizontal alignment switch (cell.RenderHorAlign) { default: case ReoGridRenderHorAlign.Left: this.controlAdapter.SetEditControlAlignment(ReoGridHorAlign.Left); x = cell.Left * scale + 1 + cellIndentSize; break; case ReoGridRenderHorAlign.Center: this.controlAdapter.SetEditControlAlignment(ReoGridHorAlign.Center); x = (cell.Left * scale + (((cell.Width - 1) * scale - 1) - width) / 2) + 1; break; case ReoGridRenderHorAlign.Right: this.controlAdapter.SetEditControlAlignment(ReoGridHorAlign.Right); x = (cell.Right - 1) * scale - width - cellIndentSize; break; } if (cell.InnerStyle.HAlign == ReoGridHorAlign.DistributedIndent) { this.controlAdapter.SetEditControlAlignment(ReoGridHorAlign.Center); } #endregion // Horizontal alignment RGFloat y = cell.Top * scale + 1; //this.viewportController.CellPositionToControl( var activeViewport = viewportController.FocusView as IViewport; int boxX = (int)Math.Round(x + viewportController.FocusView.Left - (activeViewport == null ? 0 : (activeViewport.ViewLeft * scale))); int boxY = (int)Math.Round(y + viewportController.FocusView.Top - (activeViewport == null ? 0 : (activeViewport.ViewTop * scale))); RGFloat height = (cell.Height - 1) * scale - 1; if (!cell.IsMergedCell && cell.InnerStyle.TextWrapMode != TextWrapMode.NoWrap) { if (height < cell.TextBounds.Height) { height = cell.TextBounds.Height; } } int offsetHeight = 0; // (int)Math.Round(height);// (int)Math.Round(height + 2 - (cell.Height)); if (offsetHeight > 0) { switch (cell.InnerStyle.VAlign) { case ReoGridVerAlign.Top: break; default: case ReoGridVerAlign.Middle: boxY -= offsetHeight / 2; break; case ReoGridVerAlign.Bottom: boxY -= offsetHeight; break; } } Rectangle rect = new Rectangle(boxX, boxY, width, height); this.controlAdapter.ShowEditControl(rect, cell); return(true); }