private void Grid_SelectionChanging(object sender, Syncfusion.Windows.Controls.Grid.GridSelectionChangingEventArgs e)
 {
     if (e.Range.Contains(GridRangeInfo.Row(0)) || e.Range.Contains(GridRangeInfo.Col(0)))
     {
         e.Cancel = true;
     }
 }
Beispiel #2
0
 void OnRowValidating(object sender, GridDataRowValidatingEventArgs args)
 {
     if (IsCellValidating)
         return;
     Products p;
     if (args.Record is RecordEntry)
         p = (args.Record as RecordEntry).Data as Products;
     else
         p = args.Record as Products;
     if (this.Validate("", null, null, p))
     {
         this.SetErrorInformation(args.RowIndex, ErrorMessageforRowValidation);
         //To Change the Background and set the error tooltip.
         this.Grid.Model.RowStyles[args.RowIndex].Background = new SolidColorBrush(GridUtil.GetXamlConvertedValue<Color>("#FFFFD0D0"));
         this.Grid.Model.RowStyles[args.RowIndex].CellValue2 = "Error";
         this.Grid.Model.RowStyles[args.RowIndex].Tag = ErrorMessageforRowValidation;
         this.Grid.Model.RowStyles[args.RowIndex].ShowTooltip = true;
         this.Grid.Model.RowStyles[args.RowIndex].TooltipTemplateKey = "myTooltipTemplate";
         this.Grid.Model.InvalidateCell(GridRangeInfo.Row(args.RowIndex));
         errorRowIndex = args.RowIndex;
         args.IsValid = false;
     }
     else
     {
         errorRowIndex = -1;
         ErrorMsg = "";
         args.IsValid = true;
         //Need to revert the color once error cleared in the row.
         this.AssociatedObject.Model.RowStyles[args.RowIndex].ShowTooltip = false;
         this.AssociatedObject.Model.RowStyles[args.RowIndex].Background = Brushes.Transparent;
         this.AssociatedObject.Model.InvalidateCell(GridRangeInfo.Row(args.RowIndex));
     }
 }
Beispiel #3
0
        //sets back color and text color.
        private void HandleAClick(object sender, GridCellClickEventArgs e)
        {
            if (e.RowIndex > 52 && e.ColIndex == 6 && e.RowIndex <= 60)
            {
                GridStyleInfo style = this.gridControl1[e.RowIndex, e.ColIndex];
                if (style.CellValue.ToString() == "0")
                {
                    style.CellValue = 1;

                    for (int l = 2; l <= 7; l++)
                    {
                        //set the backcolor of the cell
                        gridControl1[e.RowIndex, l].BackColor = Color.FromArgb(206, 213, 231);
                    }
                    //set the textcolor of the cell
                    this.gridControl1.RowStyles[e.RowIndex].TextColor = Color.RoyalBlue;
                }
                else
                {
                    style.CellValue = 0;
                    this.gridControl1.RowStyles[e.RowIndex].TextColor = Color.Black;
                }
            }
            this.gridControl1.RefreshRange(GridRangeInfo.Row(e.RowIndex));
        }
        private void DrawRowLines(PaintEventArgs pe)
        {
            if (PageBreakRows.Count > 0)
            {
                foreach (int row in PageBreakRows)
                {
                    if (row > grid.ViewLayout.LastVisibleRow ||
                        (row == grid.ViewLayout.LastVisibleRow && grid.ViewLayout.HasPartialVisibleRows))
                    {
                        break;
                    }
                    if (row < grid.TopRowIndex)
                    {
                        continue;
                    }

                    Rectangle rect = grid.RangeInfoToRectangle(GridRangeInfo.Row(row));

                    using (Pen p = new Pen(LineColor, LineWidth))
                    {
                        Region region = pe.Graphics.Clip;
                        pe.Graphics.Clip = new Region(grid.RangeInfoToRectangle(grid.ViewLayout.VisibleCellsRange));
                        pe.Graphics.DrawLine(p, rect.Left, rect.Bottom, rect.Right, rect.Bottom);
                        pe.Graphics.Clip = region;
                    }
                }
            }
        }
Beispiel #5
0
        protected override void OnSelectionChanged(GridSelectionChangedEventArgs e)
        {
            base.OnSelectionChanged(e);
            if (e.Reason == GridSelectionReason.MouseDown || e.Reason == GridSelectionReason.SetCurrentCell || e.Reason == GridSelectionReason.MouseMove || e.Reason == GridSelectionReason.SelectRange || e.Reason == GridSelectionReason.MouseUp)
            {
                this.InvalidateCell(GridRangeInfo.Row(0));
                this.InvalidateCell(GridRangeInfo.Col(0));
                GridRangeInfo range = e.Range;
                if (e.Range.IsCols)
                {
                    range = GetExpandedRange(range);
                }
                if (e.Range.IsRows)
                {
                    range = GetExpandedRange(range);
                }
                if (e.Range.IsTable)
                {
                    range = GetExpandedRange(range);
                }

                if (e.Range == null || e.Range.IsEmpty)
                {
                    CellLocationText = "";
                }
                else if ((e.Range.Height == 1 && e.Range.Width == 1) || e.Reason == GridSelectionReason.MouseUp)
                {
                    CellLocationText = string.Format("{0}{1}", GridRangeInfo.GetAlphaLabel(range.Left), range.Top);
                }
                else
                {
                    CellLocationText = string.Format("{0}R x {1}C", range.Height, range.Width);
                }
            }
        }
 void AssociatedObject_SelectionChanged(object sender, GridSelectionChangedEventArgs e)
 {
     if (e.Reason == GridSelectionReason.MouseDown || e.Reason == GridSelectionReason.SetCurrentCell || e.Reason == GridSelectionReason.MouseMove || e.Reason == GridSelectionReason.SelectRange || e.Reason == GridSelectionReason.MouseUp)
     {
         this.AssociatedObject.InvalidateCell(GridRangeInfo.Row(0));
         this.AssociatedObject.InvalidateCell(GridRangeInfo.Col(0));
     }
 }
        private void grid_CurrentCellMoved(object sender, GridCurrentCellMovedEventArgs e)
        {
            GridCurrentCell cc = this.grid.CurrentCell;

            this.grid.RefreshRange(GridRangeInfo.Cell(0, cc.MoveFromColIndex));
            this.grid.RefreshRange(GridRangeInfo.Cell(0, cc.MoveToColIndex));
            this.grid.RefreshRange(GridRangeInfo.Row(cc.MoveToRowIndex));
            this.grid.RefreshRange(GridRangeInfo.Row(cc.MoveFromRowIndex));
        }
Beispiel #8
0
 void t_Tick(object sender, EventArgs e)
 {
     if (dt.Rows.Count != pcount)
     {
         pcount = dt.Rows.Count;
         this.output.RowCount = dt.Rows.Count;
         this.output.PopulateValues(GridRangeInfo.Cells(1, 1, dt.Rows.Count, dt.Columns.Count), dt);
         this.output.ScrollCellInView(GridRangeInfo.Row(dt.Rows.Count));
         this.output.CurrentCell.MoveTo(GridRangeInfo.Row(dt.Rows.Count));
         this.output.Invalidate();
     }
 }
        /// <summary>
        /// Handles the CurrentCellChanged event of the AssociatedObject control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="args">The <see cref="Syncfusion.Windows.ComponentModel.SyncfusionRoutedEventArgs"/> instance containing the event data.</param>
        void AssociatedObject_CurrentCellChanged(object sender, Syncfusion.Windows.ComponentModel.SyncfusionRoutedEventArgs args)
        {
            GridDataControl _dataGrid = this.AssociatedObject;
            //Getting the index of VisibleColumn from ColumnIndex of Grid
            var columnIndex = _dataGrid.Model.ResolvePositionToVisibleColumnIndex(_dataGrid.Model.CurrencyManager.CurrentCell.ColumnIndex);

            if (columnIndex >= 0)
            {
                var column      = _dataGrid.Model.TableProperties.VisibleColumns[columnIndex];
                var recordIndex = _dataGrid.Model.CurrencyManager.CurrentRecordIndex;
                //Adding condition check to handle Unbound column values alone
                if (column.MappingName == "Status")
                {
                    var checkbx = _dataGrid.Model.CurrencyManager.CurrentCell.Renderer.CurrentCellUIElement;
                    var key     = (_dataGrid.Model.View.Records[recordIndex].Data as CountryDetails).CountryName;

                    bool _containsValue = false;
                    _containsValue = UnboundColumnDictionary_dataGrid1.ContainsKey(key);
                    //Updation the checkbox value in dictionary and calculation the summary value based on the check box state
                    if (_containsValue)
                    {
                        UnboundColumnDictionary_dataGrid1[key] = (bool)(checkbx as CheckBox).IsChecked;
                        if ((bool)(checkbx as CheckBox).IsChecked)
                        {
                            PopulationSummary        += (_dataGrid.Model.View.Records[recordIndex].Data as CountryDetails).Population;
                            AreaSummary              += (_dataGrid.Model.View.Records[recordIndex].Data as CountryDetails).Area;
                            PopulationDensitySummary += (_dataGrid.Model.View.Records[recordIndex].Data as CountryDetails).PopulationDensity;
                            if (PopulationDensitySummary < 0)
                            {
                                PopulationDensitySummary = 0;
                            }
                            TotoalCount_dataGrid1 = TotoalCount_dataGrid1 + 1;
                        }
                        else
                        {
                            PopulationSummary        -= (_dataGrid.Model.View.Records[recordIndex].Data as CountryDetails).Population;
                            AreaSummary              -= (_dataGrid.Model.View.Records[recordIndex].Data as CountryDetails).Area;
                            PopulationDensitySummary -= (_dataGrid.Model.View.Records[recordIndex].Data as CountryDetails).PopulationDensity;
                            if (PopulationDensitySummary < 0)
                            {
                                PopulationDensitySummary = 0;
                            }
                            TotoalCount_dataGrid1 = TotoalCount_dataGrid1 - 1;
                        }

                        //Invalidation the last Unbound row to refresh with  new summary values
                        _dataGrid.Model.InvalidateCell(GridRangeInfo.Row(_dataGrid.Model.RowCount - 1));
                        _dataGrid.Model.InvalidateCell(GridRangeInfo.Col(0));
                    }
                }
            }
        }
        private void OnSourceListItemAdded(ListChangedEventArgs e)
        {
            //Console.WriteLine("OnSourceListItemAdded: {0} {1}", e.NewIndex, ((DataRowView) SourceList[e.NewIndex])[0]);
            int rowIndex = e.NewIndex + 1;

            BlinkQueueInsertRecord(e.NewIndex, null);
            Model.InsertRows(rowIndex, 1);
            //InsertDirtyCellRows(rowIndex, 1, null);

            // Generate missing ChangedFieldInfo objects
            PrepareItemAdded(SourceList[e.NewIndex]);

            Blink(e);
            object item = SourceList[e.NewIndex];

            for (int n = 0; n < _pdc.Count; n++)
            {
                int columnIndex       = n + 1;
                PropertyDescriptor pd = _pdc[n];
                if (pd.PropertyType == typeof(double))
                {
                    object value = pd.GetValue(item);
                    if (value != null && !(value is DBNull))
                    {
                        _totals[n] += Convert.ToDouble(value);
                        if (!_invalidateWholeSummaryRow)
                        {
                            InvalidateCell(new RowColumnIndex(SourceList.Count + 1, columnIndex));
                        }
                    }
                }
            }
            if (_invalidateWholeSummaryRow)
            {
                InvalidateCell(GridRangeInfo.Row(SourceList.Count + 1));
            }
            if (rowIndex < TopRowIndex)
            {
                VScrollBar.Value += RowHeights[rowIndex];
            }

            InvalidateVisual(true);
        }
Beispiel #11
0
        public MainWindow()
        {
            InitializeComponent();
            grid.Model.RowCount    = 10;
            grid.Model.ColumnCount = 8;
            grid.Model.RowStyles[0].Borders.All = new Pen(Brushes.LightGray, 1);
            grid.Model.ColStyles[0].Borders.All = new Pen(Brushes.LightGray, 1);

            for (int i = 0; i < 10; i++)
            {
                for (int j = 0; j < 8; j++)
                {
                    grid.Model[i, j].CellValue = "R" + i + "C" + j;
                }
            }

            //Programmatically select the row and column
            grid.Model.Selections.Add(GridRangeInfo.Row(4));
            grid.Model.Selections.Add(GridRangeInfo.Col(3));
        }
        private void OnSourceListItemDeleted(ListChangedEventArgs e)
        {
            //Console.WriteLine("OnSourceListItemDeleted");
            int rowIndex = e.NewIndex + 1;

            if (rowIndex < TopRowIndex)
            {
                VScrollBar.Value -= RowHeights[rowIndex];
            }

            Model.RemoveRows(rowIndex, 1);
            //RemoveDirtyCellRows(rowIndex, 1, null);
            //RemoveDirtyCellRows(rowIndex, 1, null);
            BlinkQueueDeleteRecord(e.NewIndex, null);

            foreach (ChangedFieldInfo fi in GetChangedFields())
            {
                int columnIndex       = fi.FieldIndex + 1;
                PropertyDescriptor pd = _pdc[columnIndex - 1];
                if (pd.PropertyType == typeof(double))
                {
                    object value = fi.OldValue;
                    if (value != null && !(value is DBNull))
                    {
                        _totals[columnIndex - 1] -= Convert.ToDouble(value);
                        if (!_invalidateWholeSummaryRow)
                        {
                            InvalidateCell(new RowColumnIndex(SourceList.Count + 1, columnIndex));
                        }
                    }
                }
            }
            if (_invalidateWholeSummaryRow)
            {
                InvalidateCell(GridRangeInfo.Row(SourceList.Count + 1));
            }

            InvalidateVisual(true);
        }
Beispiel #13
0
        private void PerformSearch()
        {
            SelectRecordEmpty   = String.IsNullOrWhiteSpace(SelectRecordCondition);
            SelectFieldEmpty    = String.IsNullOrWhiteSpace(SelectFieldCondition);
            SelectSubfieldEmpty = String.IsNullOrWhiteSpace(SelectSubfieldCondition);

            find_replaceScriptEditor.SearchScriptResultList = new List <SearchScriptResult>();

            IrbisRecord     Record;
            MatchCollection searchMatches;
            List <MyMatch>  searchMatchesList;

            RecordField[] fields;
            int           fieldOcc;
            String        fieldText, fieldTextProtected;
            int           index0, index1, index2;

            String[] RecordStr   = new string[] { "Record" };
            String[] FieldStr    = new string[] { "Field" };
            String[] SubFieldStr = new string[] { "Subfield" };

            RegexOptions regexMatchCase = find_replaceScriptEditor.chkMatchCase.Checked ? RegexOptions.IgnoreCase : RegexOptions.None;
            int          index          = 0;

            StringBuilder templateProlog = new StringBuilder();

            if (templateMode == TemplateMode.T4)
            {
                templateProlog.AppendLine("<#@ template language=\"C#\" #>");
                templateProlog.AppendLine("<#@ assembly name=\"System.Core.dll\" #>");
                templateProlog.AppendLine("<#@ import namespace=\"System.Collections.Generic\" #>");
                templateProlog.AppendLine("<#@ assembly name=\"$(ProjectDir)$(OutDir)ManagedClient.dll\" #>");
                templateProlog.AppendLine("<#@ import namespace=\"ManagedClient\" #>");
                templateProlog.AppendLine("<#@ parameter type=\"ManagedClient64\" name=\"client\" #>");
            }
            else
            {
                templateProlog.AppendLine("@using ManagedClient");
                templateProlog.AppendLine("@using IrbisRecordsProcessing");
                templateProlog.AppendLine("@{ String EoL = Environment.NewLine; }");
            }

            ScriptEngine.Globals.SetVariable("client", find_replaceScriptEditor.client);
            ScriptEngine.Globals.SetVariable("curDatabase", find_replaceScriptEditor.curDatabase);


            StringBuilder templatePrologStr;

            if (workMode == WorkMode.Script)
            {
                RemObjectUtils.ScriptRun(ScriptEngine, find_replaceScriptEditor.PrologScriptCode);
            }
            else if (workMode == WorkMode.Template)
            {
                if (templateMode == TemplateMode.T4)
                {
                    Utils.AppendGeneratedT4Template(find_replaceScriptEditor.PrologTemplate.Text, templateProlog, ref templateStringBuilder, find_replaceScriptEditor.client);
                }
                else
                {
                    Utils.AppendGeneratedRazorTemplate(find_replaceScriptEditor.PrologTemplate.Text, templateProlog, ref templateStringBuilder,
                                                       new { client = find_replaceScriptEditor.client });
                }
            }

            int[] mfnRange = find_replaceScriptEditor.recordsData.MfnList;


            foreach (int mfn in mfnRange)
            {
                if (backgroundWorker.CancellationPending)
                {
                    cancelled = true;
                    break;
                }

                Record = find_replaceScriptEditor.client.ReadRecord(mfn);
                backgroundWorker.ReportProgress((int)(((float)mfn / find_replaceScriptEditor.curDatabase.Length) * 100));

                if (workMode == WorkMode.Template)
                {
                    templatePrologStr = new StringBuilder();
                    templatePrologStr.Append(templateProlog);
                    if (templateMode == TemplateMode.T4)
                    {
                        templatePrologStr.Append(templateProlog).AppendLine("<#@ parameter type=\"IrbisRecord\" name=\"record\" #>");
                        Utils.AppendGeneratedT4Template(find_replaceScriptEditor.WorkingTemplate.Text, templatePrologStr, ref templateStringBuilder, find_replaceScriptEditor.client, Record);
                    }
                    else
                    {
                        Utils.AppendGeneratedRazorTemplate(find_replaceScriptEditor.WorkingTemplate.Text, templatePrologStr, ref templateStringBuilder,
                                                           new { client = find_replaceScriptEditor.client, record = Record });
                    }
                    continue;
                }

                if (SelectRecordEmpty || RemObjectUtils.ScriptEval(ScriptEngine, SelectRecordCondition, RecordStr, Record))
                {
                    if (workMode == WorkMode.Script)
                    {
                        RemObjectUtils.ScriptRun(ScriptEngine, find_replaceScriptEditor.PrologRecordScriptCode, RecordStr, Record);
                        if (String.IsNullOrWhiteSpace(find_replaceScriptEditor.SubfieldScriptCode) && String.IsNullOrWhiteSpace(find_replaceScriptEditor.SubfieldScriptCode))
                        {
                            RemObjectUtils.ScriptRun(ScriptEngine, find_replaceScriptEditor.EpilogRecordScriptCode);
                            continue;
                        }
                    }

                    foreach (RecordField Field in Record.Fields)
                    {
                        searchMatchesList  = new List <MyMatch>();
                        fieldText          = Field.ToText();
                        fieldTextProtected = Regex.Replace(fieldText, "\\^\\S", "  ");

                        if (SelectFieldEmpty || RemObjectUtils.ScriptEval(ScriptEngine, SelectFieldCondition, FieldStr, Field))
                        {
                            if (workMode == WorkMode.Script)
                            {
                                RemObjectUtils.ScriptRun(ScriptEngine, find_replaceScriptEditor.FieldScriptCode, FieldStr, Field);
                                if (String.IsNullOrWhiteSpace(find_replaceScriptEditor.SubfieldScriptCode))
                                {
                                    continue;
                                }
                            }

                            if (SelectSubfieldEmpty && workMode != WorkMode.Script)
                            {
                                searchMatches = Regex.Matches(fieldText, FindTextStr, regexMatchCase);
                                foreach (Match nextMatch in searchMatches)
                                {
                                    MyMatch newMatch = new MyMatch();
                                    newMatch.Value = nextMatch.Value;
                                    newMatch.Index = nextMatch.Index;
                                    searchMatchesList.Add(newMatch);
                                }
                            }
                            else
                            {
                                foreach (SubField Subfield in Field.SubFields)
                                {
                                    if (SelectSubfieldEmpty || RemObjectUtils.ScriptEval(ScriptEngine, SelectSubfieldCondition, SubFieldStr, Subfield))
                                    {
                                        if (workMode == WorkMode.Script)
                                        {
                                            RemObjectUtils.ScriptRun(ScriptEngine, find_replaceScriptEditor.SubfieldScriptCode, SubFieldStr, Subfield);
                                            continue;
                                        }

                                        searchMatches = Regex.Matches(Subfield.Text, FindTextStr, regexMatchCase);

                                        foreach (Match nextMatch in searchMatches)
                                        {
                                            MyMatch newMatch = new MyMatch();
                                            newMatch.Value = nextMatch.Value;
                                            newMatch.Index = nextMatch.Index + fieldText.IndexOf("^" + Subfield.Code) + 2;

                                            searchMatchesList.Add(newMatch);
                                        }
                                    }
                                }
                            }


                            if (workMode == WorkMode.Script)
                            {
                                continue;
                            }

                            foreach (MyMatch nextMatch in searchMatchesList)
                            {
                                SearchScriptResult searchScriptResult = new SearchScriptResult();
                                searchScriptResult.foundStr = nextMatch.Value;
                                searchScriptResult.index    = nextMatch.Index;
                                searchScriptResult.mfn      = mfn;

                                index0 = searchScriptResult.index;
                                if (index0 > 0)
                                {
                                    index1 = fieldTextProtected.LastIndexOf(" ", index0 - 1);
                                }
                                else
                                {
                                    index1 = 0;
                                }
                                if (index1 == -1)
                                {
                                    index1 = 0;
                                }

                                index0 += searchScriptResult.foundStr.Length;

                                if (index0 < fieldTextProtected.Length - 1)
                                {
                                    index2 = fieldTextProtected.IndexOf(" ", index0);
                                }
                                else
                                {
                                    index2 = -1;
                                }

                                if (index2 == -1)
                                {
                                    index2 = fieldTextProtected.Length;
                                }

                                if (index1 > 0)
                                {
                                    searchScriptResult.contextStr = fieldTextProtected.Substring(index1 + 1, index2 - index1 - 1);
                                }
                                else
                                {
                                    searchScriptResult.contextStr = fieldTextProtected.Substring(0, index2);
                                }

                                index++;

                                if (find_replaceScriptEditor.activeTabIndex != 0)
                                {
                                    searchScriptResult.replaceToStr = Regex.Replace(nextMatch.Value, FindTextStr, ReplaceTextStr, regexMatchCase);

                                    searchScriptResult.contextModStr = Regex.Replace(searchScriptResult.contextStr, FindTextStr, ReplaceTextStr, regexMatchCase);

                                    searchScriptResult.fieldTag = Field.Tag;

                                    fields = Record.Fields.GetField(Field.Tag);
                                    for (fieldOcc = 0; fieldOcc < fields.Length; fieldOcc++)
                                    {
                                        if (fields[fieldOcc] == Field)
                                        {
                                            break;
                                        }
                                    }
                                    searchScriptResult.fieldOcc = fieldOcc;

                                    find_replaceScriptEditor.SearchScriptResultList.Add(searchScriptResult);

                                    if (!backgroundWorker.CancellationPending)
                                    {
                                        this.Invoke((MethodInvoker) delegate
                                        {
                                            AdvStringGrid.BeginUpdate();
                                            AdvStringGrid.RowCount             = index;
                                            AdvStringGrid[index, 1].Text       = searchScriptResult.foundStr;
                                            AdvStringGrid[index, 2].Text       = searchScriptResult.replaceToStr;
                                            AdvStringGrid[index, 3].Text       = searchScriptResult.contextStr;
                                            AdvStringGrid[index, 4].Text       = searchScriptResult.contextModStr;
                                            AdvStringGrid[index, 5].CellType   = GridCellTypeName.ComboBox;
                                            AdvStringGrid[index, 5].DataSource = applyActions;
                                            AdvStringGrid[index, 5].CellValue  = applyActions[0];
                                            AdvStringGrid.ScrollCellInView(GridRangeInfo.Row(index), GridScrollCurrentCellReason.Any);
                                            AdvStringGrid.EndUpdate();
                                        });
                                    }
                                    else
                                    {
                                        cancelled = true;
                                        break;
                                    }
                                }
                                else
                                {
                                    find_replaceScriptEditor.SearchScriptResultList.Add(searchScriptResult);

                                    if (!backgroundWorker.CancellationPending)
                                    {
                                        this.Invoke((MethodInvoker) delegate
                                        {
                                            AdvStringGrid.BeginUpdate();
                                            AdvStringGrid.RowCount       = index;
                                            AdvStringGrid[index, 1].Text = searchScriptResult.foundStr;
                                            AdvStringGrid[index, 2].Text = searchScriptResult.contextStr;
                                            AdvStringGrid.ScrollCellInView(GridRangeInfo.Row(index), GridScrollCurrentCellReason.Any);
                                            AdvStringGrid.EndUpdate();
                                        });
                                    }
                                    else
                                    {
                                        cancelled = true;
                                        break;
                                    }
                                }
                            }
                        }
                    }
                }
                if (workMode == WorkMode.Script)
                {
                    RemObjectUtils.ScriptRun(ScriptEngine, find_replaceScriptEditor.EpilogRecordScriptCode);
                }
            }

            if (workMode == WorkMode.Script)
            {
                RemObjectUtils.ScriptRun(ScriptEngine, find_replaceScriptEditor.EpilogScriptCode);
            }
            else if (workMode == WorkMode.Template)
            {
                if (templateMode == TemplateMode.T4)
                {
                    Utils.AppendGeneratedT4Template(find_replaceScriptEditor.EpilogTemplate.Text, templateProlog, ref templateStringBuilder, find_replaceScriptEditor.client);
                }
                else
                {
                    Utils.AppendGeneratedRazorTemplate(find_replaceScriptEditor.EpilogTemplate.Text, templateProlog, ref templateStringBuilder,
                                                       new { client = find_replaceScriptEditor.client });
                }
            }
        }
Beispiel #14
0
 protected override void OnPrepareRenderCell(GridPrepareRenderCellEventArgs e)
 {
     base.OnPrepareRenderCell(e);
     if (e.Cell.RowIndex == 0 && Model.SelectedRanges.AnyRangeIntersects(GridRangeInfo.Col(e.Cell.ColumnIndex)))
     {
         e.Style.Background      = Brushes.LightGray;
         e.Style.Font.FontWeight = FontWeights.Bold;
     }
     else if (e.Cell.ColumnIndex == 0 && Model.SelectedRanges.AnyRangeIntersects(GridRangeInfo.Row(e.Cell.RowIndex)))
     {
         e.Style.Background      = Brushes.LightGray;
         e.Style.Font.FontWeight = FontWeights.Bold;
     }
 }
Beispiel #15
0
 void gridControl1_CurrentCellErrorMessage(object sender, GridCurrentCellErrorMessageEventArgs e)
 {
     this.gridControl1.RefreshRange(GridRangeInfo.Row(this.gridControl1.CurrentCell.RowIndex));
 }
Beispiel #16
0
 void gridControl1_KeyUp(object sender, KeyEventArgs e)
 {
     this.gridControl1.RefreshRange(GridRangeInfo.Row(this.gridControl1.CurrentCell.RowIndex));
 }
Beispiel #17
0
        private void InitializeGrid()
        {
            this.gridControl1.BeginUpdate();

            #region Cell Styles
            gridControl1.TableStyle.FloatCell = true;
            gridControl1.FloatCellsMode       = GridFloatCellsMode.BeforeDisplayCalculation;
            gridControl1.ColWidths[3]        *= 2;
            gridControl1.CoveredRanges.Add(GridRangeInfo.Cells(1, 1, 2, gridControl1.ColCount));
            gridControl1[1, 1].CellValue           = "DropDown Cells";
            gridControl1[1, 1].Font.Size           = 14;
            gridControl1[1, 1].Font.Bold           = true;
            gridControl1[1, 1].VerticalAlignment   = GridVerticalAlignment.Middle;
            gridControl1[1, 1].HorizontalAlignment = GridHorizontalAlignment.Center;
            gridControl1[1, 1].CellType            = "Static";
            this.gridControl1.CheckBoxClick       += new GridCellClickEventHandler(gridControl1_CheckBoxClick);
            #endregion

            #region DataSources
            //
            // Creating DataSource
            //
            StringCollection items = new StringCollection();
            items.Add("One");
            items.Add("Two");
            items.Add("Three");
            items.Add("Four");
            items.Add("Five");
            items.Add("Six");
            items.Add("Seven");
            items.Add("Eight");
            items.Add("Nine");
            items.Add("Ten");
            ImageList imageList = new ImageList();
            imageList.Images.Add(SystemIcons.Warning.ToBitmap());
            imageList.Images.Add(SystemIcons.Application.ToBitmap());
            imageList.Images.Add(SystemIcons.Asterisk.ToBitmap());
            imageList.Images.Add(SystemIcons.Error.ToBitmap());
            imageList.Images.Add(SystemIcons.Information.ToBitmap());
            imageList.Images.Add(SystemIcons.Question.ToBitmap());
            this.gridControl1.TableStyle.ImageList = imageList;

            ArrayList icons = new ArrayList();
            icons.Add(new IconDesc("Warning", "WA", 0));
            icons.Add(new IconDesc("Application", "AP", 1));
            icons.Add(new IconDesc("Asterisk", "AS", 2));
            icons.Add(new IconDesc("Error", "ER", 3));
            icons.Add(new IconDesc("Information", "INF", 4));
            icons.Add(new IconDesc("Question", "QUE", 5));

            #endregion

            #region ComboBox Cells
            this.gridControl1.Model.EnableGridListControlInComboBox = false;
            int rowIndex = 4;
            gridControl1.CoveredRanges.Add(GridRangeInfo.Cells(rowIndex, 1, rowIndex, gridControl1.ColCount));
            gridControl1[rowIndex, 1].CellType    = GridCellTypeName.CheckBox;
            gridControl1[rowIndex, 1].Description = "ComboBox with AutoComplete in Editmode";
            gridControl1[rowIndex, 1].Font.Bold   = true;
            AddChoices(ref rowIndex, "ComboBox", items, null, "", "");
            for (int i = 5; i <= 8; i++)
            {
                this.gridControl1.HideRows[i] = true;
            }

            // ComboBox using ChoiceList
            rowIndex = 10;
            gridControl1.CoveredRanges.Add(GridRangeInfo.Cells(rowIndex - 1, 1, rowIndex - 1, gridControl1.ColCount));
            gridControl1.CoveredRanges.Add(GridRangeInfo.Cells(rowIndex, 1, rowIndex, gridControl1.ColCount));
            gridControl1[rowIndex, 1].CellType    = GridCellTypeName.CheckBox;
            gridControl1[rowIndex, 1].Description = "ComboBox using ChoiceList";
            gridControl1[rowIndex, 1].Font.Bold   = true;
            gridControl1.RowHeights.ResizeToFit(GridRangeInfo.Row(rowIndex), GridResizeToFitOptions.ResizeCoveredCells);
            AddEntries(ref rowIndex, "ComboBox", items, null, "", "");
            for (int i = 11; i <= 19; i++)
            {
                this.gridControl1.HideRows[i] = true;
            }

            //ComboBox using Datasource";
            rowIndex = 21;
            gridControl1.CoveredRanges.Add(GridRangeInfo.Cells(rowIndex - 1, 1, rowIndex - 1, gridControl1.ColCount));
            gridControl1.CoveredRanges.Add(GridRangeInfo.Cells(rowIndex, 1, rowIndex, gridControl1.ColCount));
            gridControl1[rowIndex, 1].CellType    = GridCellTypeName.CheckBox;
            gridControl1[rowIndex, 1].Description = "ComboBox using Datasource, DisplayMember = CompanyName";
            gridControl1[rowIndex, 1].Font.Bold   = true;
            gridControl1.RowHeights.ResizeToFit(GridRangeInfo.Row(rowIndex), GridResizeToFitOptions.ResizeCoveredCells);
            AddEntries(ref rowIndex, "ComboBox", null, dataSet11.Customers, "CustomerID", "CompanyName");
            for (int i = 22; i <= 30; i++)
            {
                this.gridControl1.HideRows[i] = true;
            }

            rowIndex = 32;
            gridControl1.CoveredRanges.Add(GridRangeInfo.Cells(rowIndex - 1, 1, rowIndex - 1, gridControl1.ColCount));
            gridControl1.CoveredRanges.Add(GridRangeInfo.Cells(rowIndex, 1, rowIndex, gridControl1.ColCount));
            gridControl1[rowIndex, 1].CellType    = GridCellTypeName.CheckBox;
            gridControl1[rowIndex, 1].Description = "ComboBox using Datasource, ValueMember = empty ";
            gridControl1[rowIndex, 1].Font.Bold   = true;
            gridControl1.RowHeights.ResizeToFit(GridRangeInfo.Row(rowIndex), GridResizeToFitOptions.ResizeCoveredCells);
            AddEntries(ref rowIndex, "ComboBox", null, dataSet11.Customers, "", "CompanyName");
            for (int i = 33; i <= 41; i++)
            {
                this.gridControl1.HideRows[i] = true;
            }

            rowIndex = 3;
            gridControl1.CoveredRanges.Add(GridRangeInfo.Cells(rowIndex, 1, rowIndex, gridControl1.ColCount));
            gridControl1[rowIndex, 1].CellType  = GridCellTypeName.Static;
            gridControl1[rowIndex, 1].Text      = "ComboBox Cells :    Following Categories illustrates the features supported by a ComboBox cell";
            gridControl1[rowIndex, 1].TextColor = Color.Black;
            gridControl1[rowIndex, 1].Font.Bold = true;

            #endregion

            #region GridListControl Cells
            rowIndex = 46;
            gridControl1.CoveredRanges.Add(GridRangeInfo.Cells(rowIndex - 1, 1, rowIndex - 1, gridControl1.ColCount));
            gridControl1.CoveredRanges.Add(GridRangeInfo.Cells(rowIndex, 1, rowIndex, gridControl1.ColCount));
            gridControl1[rowIndex, 1].CellType    = GridCellTypeName.CheckBox;
            gridControl1[rowIndex, 1].Description = "GridListControl using Datasource, DisplayMember = CompanyName";
            gridControl1[rowIndex, 1].Font.Bold   = true;
            gridControl1.RowHeights.ResizeToFit(GridRangeInfo.Row(rowIndex), GridResizeToFitOptions.ResizeCoveredCells);
            AddEntries(ref rowIndex, "GridListControl", null, dataSet11.Customers, "CustomerID", "CompanyName");
            for (int i = 47; i <= 55; i++)
            {
                this.gridControl1.HideRows[i] = true;
            }

            rowIndex = 57;
            gridControl1.CoveredRanges.Add(GridRangeInfo.Cells(rowIndex - 1, 1, rowIndex - 1, gridControl1.ColCount));
            gridControl1.CoveredRanges.Add(GridRangeInfo.Cells(rowIndex, 1, rowIndex, gridControl1.ColCount));
            gridControl1[rowIndex, 1].CellType    = GridCellTypeName.CheckBox;
            gridControl1[rowIndex, 1].Description = "GridListControl using Datasource, ValueMember = empty";
            gridControl1[rowIndex, 1].Font.Bold   = true;
            gridControl1.RowHeights.ResizeToFit(GridRangeInfo.Row(rowIndex), GridResizeToFitOptions.ResizeCoveredCells);
            AddEntries(ref rowIndex, "GridListControl", null, dataSet11.Customers, "", "CompanyName");
            for (int i = 58; i <= 66; i++)
            {
                this.gridControl1.HideRows[i] = true;
            }


            rowIndex = 68;
            gridControl1.CoveredRanges.Add(GridRangeInfo.Cells(rowIndex - 1, 1, rowIndex - 1, gridControl1.ColCount));
            gridControl1.CoveredRanges.Add(GridRangeInfo.Cells(rowIndex, 1, rowIndex, gridControl1.ColCount));
            gridControl1[rowIndex, 1].CellType    = GridCellTypeName.CheckBox;
            gridControl1[rowIndex, 1].Description = "GridListControl showing ArrayList with Icons";
            gridControl1[rowIndex, 1].Font.Bold   = true;
            gridControl1.RowHeights.ResizeToFit(GridRangeInfo.Row(rowIndex), GridResizeToFitOptions.ResizeCoveredCells);
            AddEntries(ref rowIndex, "GridListControl", null, icons, "", "LongName");
            for (int i = 69; i <= 77; i++)
            {
                this.gridControl1.HideRows[i] = true;
            }

            rowIndex = 43;
            gridControl1.CoveredRanges.Add(GridRangeInfo.Cells(rowIndex - 1, 1, rowIndex - 1, gridControl1.ColCount));
            gridControl1.CoveredRanges.Add(GridRangeInfo.Cells(rowIndex, 1, rowIndex, gridControl1.ColCount));
            gridControl1[rowIndex, 1].CellType  = GridCellTypeName.Static;
            gridControl1[rowIndex, 1].Text      = "GridListControl Cells :    Following Categories illustrates the features supported by a GridListControl cell";
            gridControl1[rowIndex, 1].TextColor = Color.Black;
            gridControl1[rowIndex, 1].Font.Bold = true;
            rowIndex++;
            gridControl1.CoveredRanges.Add(GridRangeInfo.Cells(rowIndex, 1, rowIndex, gridControl1.ColCount));
            gridControl1[rowIndex, 1].Text      = "GridListControl using ChoiceList : Not Supported";
            gridControl1[rowIndex, 1].Font.Bold = true;


            #endregion

            #region MonthCalendar Cells
            rowIndex = 79;
            gridControl1.CoveredRanges.Add(GridRangeInfo.Cells(rowIndex - 1, 1, rowIndex - 1, gridControl1.ColCount));
            gridControl1.CoveredRanges.Add(GridRangeInfo.Cells(rowIndex, 1, rowIndex, 4));
            gridControl1[rowIndex, 1].Text      = "DropDown Calendar Cells";
            gridControl1[rowIndex, 1].TextColor = Color.Black;
            gridControl1[rowIndex, 1].Font.Bold = true;
            rowIndex++;
            gridControl1[rowIndex, 1].CellType  = "MonthCalendar";
            gridControl1[rowIndex, 1].CellValue = DateTime.Now;
            gridControl1[rowIndex, 1].Font.Size = 8;
            gridControl1[rowIndex, 3].CellType  = "MonthCalendar";
            gridControl1[rowIndex, 3].CellValue = DateTime.Now;
            gridControl1[rowIndex, 3].Font.Size = 8;
            gridControl1.RowHeights[rowIndex]   = gridControl1.DefaultRowHeight - 2;

            #endregion

            #region Coloredit Cells
            rowIndex = 79;
            gridControl1.CoveredRanges.Add(GridRangeInfo.Cells(rowIndex, 5, rowIndex, gridControl1.ColCount));
            gridControl1[rowIndex, 5].Text      = "DropDown ColorEdit Cells";
            gridControl1[rowIndex, 5].TextColor = Color.Black;
            gridControl1[rowIndex, 5].Font.Bold = true;
            rowIndex++;
            gridControl1[rowIndex, 5].CellType  = GridCellTypeName.ColorEdit;
            gridControl1[rowIndex, 5].TextColor = Color.Black;
            gridControl1[rowIndex, 5].Font.Size = 8;
            gridControl1[rowIndex, 7].CellType  = GridCellTypeName.ColorEdit;
            gridControl1[rowIndex, 7].TextColor = Color.Black;
            gridControl1[rowIndex, 7].Font.Size = 8;
            gridControl1.RowHeights[rowIndex]   = gridControl1.DefaultRowHeight - 2;
            #endregion

            #region RichTextCells
            rowIndex = 82;
            gridControl1.CoveredRanges.Add(GridRangeInfo.Cells(rowIndex - 1, 1, rowIndex - 1, gridControl1.ColCount));
            gridControl1.CoveredRanges.Add(GridRangeInfo.Cells(rowIndex, 1, rowIndex, gridControl1.ColCount));
            gridControl1[rowIndex, 1].CellType    = GridCellTypeName.CheckBox;
            gridControl1[rowIndex, 1].Description = "Rich Text Cells :    Check this to view a drop-down menu which displays formatting helpers to modify the text";
            gridControl1[rowIndex, 1].TextColor   = Color.Black;
            gridControl1[rowIndex, 1].Font.Bold   = true;
            rowIndex = 83;
            rtf2     =
                @"{\rtf1\ansi" +
                // font table
                @"{\fonttbl" +
                @"\f0\froman Times New Roman; " +
                @"\f1\fdecor Courier New; " +
                @"\f2\fswiss Arial;} " +
                @"\deff0 " +
                // color table
                @"{\colortbl" +
                @"\red250\green177\blue146; " +
                @"\red229\green 118\blue145; " +
                @"\red101\green121\blue219; " +
                @"\red240\green224\blue255;} " +
                // first line
                @"\highlight2\cb1\qc\cf0\f0\fs20 12 point, Times New Roman, " +
                @"red, centered\plain\par" +
                // second line
                @"\highlight0\ql\cf3\f1\fs28 14 point, Courier New, blue, " +
                @"left aligned\plain\par" +
                // third line
                @"\highlight1\qr\cf0\f2\fs36 18 point, Arial, black, " +
                @"right aligned\plain\par" +
                // fourth line
                @"\qc Default font and color, \b Bold\plain , \ul Underline\plain , \i Italic \plain\par" +
                // closing bracket
                @"}"
            ;
            gridControl1[rowIndex, 1].CellType = "RichText";
            gridControl1[rowIndex, 1].Text     = rtf2;
            gridControl1.RowHeights[rowIndex]  = 150;
            gridControl1.CoveredRanges.Add(GridRangeInfo.Cells(rowIndex, 1, rowIndex, 5));
            this.gridControl1.HideRows[rowIndex] = true;
            #endregion

            this.gridControl1.EndUpdate(true);
        }
Beispiel #18
0
        /// <summary>
        /// Set timer clok to notify the changes
        /// </summary>
        private void m_timer_Tick(object sender, EventArgs e)
        {
            timerCount++;
            GridRangeInfo gCells = GridRangeInfo.EmptyRange();

            if (oldSize != m_syncGrid.ClientSize)
            {
                // Dispose graphics context if size was changed.
                if (g != null)
                {
                    g.Dispose();
                }
                g       = null;
                oldSize = m_syncGrid.ClientSize;
            }

            if (drawDirectToDC && g == null)
            {
                g = m_syncGrid.CreateGridGraphics();
            }

            try
            {
                for (int i = 0; i < m_numUpdatesPerTick; i++)
                {
                    int      recNum = rand.Next(m_set.Count - 1);
                    int      rowNum = recNum + 1;
                    int      col    = rand.Next(18) + 1;
                    int      colNum = col + 1;
                    object[] drow   = (object[])m_set[recNum];
                    drow[col] = rand.Next(100);
                    GridRangeInfo g1 = GridRangeInfo.Cell(rowNum, colNum);

                    gCells = GridRangeInfo.UnionRange(gCells, g1);

                    // Clear our volatile cache
                    m_syncGrid.ResetVolatileData();

                    // Handle case when values is change for current cell.
                    if (g1 == m_syncGrid.CurrentCell.RangeInfo)
                    {
                        m_syncGrid.CurrentCell.Model.ResetActiveText(rowNum, colNum);
                    }
                    else
                    {
                        // Draw direct to dc
                        if (drawDirectToDC)
                        {
                            Rectangle bounds = m_syncGrid.RangeInfoToRectangle(g1);
                            if (!bounds.IsEmpty)
                            {
                                // DrawClippedGrid method lets you simply draw the cells at the specified bounds directly to the graphics context.
                                m_syncGrid.DrawClippedGrid(g, bounds);
                            }
                        }
                    }
                }

                if (!drawDirectToDC)
                {
                    m_syncGrid.ResetVolatileData();
                    m_syncGrid.ViewLayout.Lock();  // Prevent subsequent calls to ViewLayout.Reset method from clearing the layout information. Method was added in 3.1.0.x
                    Rectangle bounds = m_syncGrid.RangeInfoToRectangle(gCells);
                    if (!bounds.IsEmpty)
                    {
                        m_syncGrid.Invalidate(bounds);
                        m_syncGrid.Update();
                    }
                    m_syncGrid.ViewLayout.Unlock();
                }

                // Insert or remove a row
                if (insertRemoveCount == 0)
                {
                    return;
                }

                if (toggleInsertRemove > 0 && (timerCount % insertRemoveModulus) == 0)
                {
                    icount       = ++icount % (toggleInsertRemove * 2);
                    shouldInsert = icount <= toggleInsertRemove;

                    Console.WriteLine(m_syncGrid.RowCount);
                    if (shouldInsert)
                    {
                        for (int ri = 0; ri < insertRemoveCount; ri++)
                        {
                            int recNum = rand.Next(m_set.Count - 1);
                            int rowNum = recNum + 1;

                            // Underlying data structure (this could be a datatable or whatever structure
                            // you use behind a virtual grid).
                            //
                            // In this case it is a ArrayList

                            int      next = rand.Next(100);
                            object[] row  = new object[] { "Hello world", next + 1, next + 2,
                                                           next + 3, next + 4, next + 5, next + 6,
                                                           next + 7, next + 8, next + 9, next + 10,
                                                           next + 11, next + 12, next + 13, next + 14,
                                                           next + 15, next + 16, next + 17,
                                                           next + 18, next + 19, next + 20 };
                            m_set.Insert(recNum, row);

                            // Now that the change was done in the underlying datasource we need
                            // to tell the grid to reflect those changes:

                            m_syncGrid.Model.ResetVolatileData();

                            // Old way:
                            if (!drawDirectToDC)
                            {
                                m_syncGrid.Rows.OnRangeInserting(new GridRangeInsertingEventArgs(rowNum, 1, null));
                                m_syncGrid.Rows.OnRangeInserted(new GridRangeInsertedEventArgs(rowNum, 1, null, true));
                                m_syncGrid.Update();
                            }
                            else
                            {
                                // Optimized way: Directly calling ScrollWindows, don't let ScrollWindow call Invalidate.

                                if (rowNum < m_syncGrid.TopRowIndex)
                                {
                                    if (!allowChangeTopRowWhenInsertBeforeView || !m_syncGrid.ViewLayout.HasPartialVisibleRows) // checks whether the last row is shown and fully visible
                                    {
                                        // in this case we need to insert at top
                                        rowNum = m_syncGrid.TopRowIndex;
                                    }
                                    else
                                    {
                                        // If record is inserted before viewable area, simply increase
                                        // the top row so that the viewable area stays the same. No
                                        // drawing of the screen is needed.
                                        m_syncGrid.InternalSetTopRow(m_syncGrid.TopRowIndex + 1);

                                        m_syncGrid.UpdateScrollBars();
                                        rowNum = -1; // mark it as handled.

                                        if (showNumberedRowHeaders)
                                        {
                                            // Repaint only row headers - they all change
                                            Rectangle rowHeaderBounds = m_syncGrid.RangeInfoToRectangle(GridRangeInfo.Col(0));
                                            m_syncGrid.DrawClippedGrid(g, rowHeaderBounds);
                                        }
                                    }
                                }

                                if (rowNum != -1)
                                {
                                    GridRangeInfo rg     = GridRangeInfo.Row(rowNum);
                                    Rectangle     bounds = m_syncGrid.RangeInfoToRectangle(rg);

                                    if (!bounds.IsEmpty)
                                    {
                                        if (showNumberedRowHeaders)
                                        {
                                            // don't scroll row header area - leave it as is (only works if all rows have same height ...)
                                            bounds.X += m_syncGrid.ColWidths[0];

                                            if (!m_syncGrid.ViewLayout.HasPartialVisibleRows)
                                            {
                                                // Repaint row headers below last row
                                                Rectangle rowHeaderBounds = m_syncGrid.RangeInfoToRectangle(GridRangeInfo.Cells(m_syncGrid.RowCount, 0, m_syncGrid.RowCount, 0));
                                                m_syncGrid.DrawClippedGrid(g, rowHeaderBounds);
                                            }
                                        }

                                        // If rows can have different heights:
                                        // m_syncGrid.ViewLayout.Reset();

                                        Rectangle scrollBounds = new Rectangle(bounds.Left, bounds.Top, bounds.Right, m_syncGrid.ClientRectangle.Bottom);
                                        m_syncGrid.ScrollWindow(0, bounds.Height, scrollBounds, scrollBounds, false);  // don't cause Invalidate being called.
                                        m_syncGrid.Model.ResetVolatileData();

                                        //									System.Threading.Thread.Sleep(1000);

                                        // DrawClippedGrid method lets you simply draw the cells at the specified bounds directly to the graphics context.
                                        m_syncGrid.DrawClippedGrid(g, bounds);
                                    }

                                    m_syncGrid.UpdateScrollBars();
                                }
                            }
                        }
                    }
                    else
                    {
                        for (int ri = 0; ri < insertRemoveCount; ri++)
                        {
                            int recNum = 5; //rand.Next(m_set.Count - 1);
                            int rowNum = recNum + 1;

                            // Underlying data structure (this could be a datatable or whatever structure
                            // you use behind a virtual grid).
                            //
                            // In this case it is a ArrayList

                            m_set.RemoveAt(recNum);

                            // Now that the change was done in the underlying datasource we need
                            // to tell the grid to reflect those changes:

                            // Old way:
                            if (!drawDirectToDC)
                            {
                                m_syncGrid.Rows.OnRangeRemoving(new GridRangeRemovingEventArgs(rowNum, rowNum + 1));
                                GridModelInsertRangeOptions iro = new GridModelInsertRangeOptions();
                                iro.RowColSizes = new int[m_syncGrid.Rows.DefaultSize];
                                m_syncGrid.Rows.OnRangeRemoved(new GridRangeRemovedEventArgs(rowNum, rowNum + 1, iro, true));
                                m_syncGrid.Update();
                            }
                            else
                            {
                                // Optimized way: Directly calling ScrollWindows, don't let ScrollWindow call Invalidate.

                                if (rowNum < m_syncGrid.TopRowIndex)
                                {
                                    if (!allowChangeTopRowWhenInsertBeforeView || !m_syncGrid.ViewLayout.HasPartialVisibleRows) // checks whether the last row is shown and fully visible
                                    {
                                        // in this case we need to insert at top
                                        rowNum = m_syncGrid.TopRowIndex;
                                    }
                                    else
                                    {
                                        // If record is inserted before viewable area, simply increase
                                        // the top row so that the viewable area stays the same. No
                                        // drawing of the screen is needed.
                                        m_syncGrid.InternalSetTopRow(m_syncGrid.TopRowIndex - 1);

                                        m_syncGrid.UpdateScrollBars();
                                        if (showNumberedRowHeaders)
                                        {
                                            // Repaint only row headers - they all change
                                            Rectangle rowHeaderBounds = m_syncGrid.RangeInfoToRectangle(GridRangeInfo.Col(0));
                                            m_syncGrid.DrawClippedGrid(g, rowHeaderBounds);
                                        }
                                        rowNum = -1; // mark it as handled.
                                    }
                                }

                                if (rowNum != -1)
                                {
                                    GridRangeInfo rg     = GridRangeInfo.Row(rowNum);
                                    Rectangle     bounds = m_syncGrid.RangeInfoToRectangle(rg);

                                    if (!bounds.IsEmpty)
                                    {
                                        if (showNumberedRowHeaders)
                                        {
                                            // don't scroll row header area - leave it as is (only works if all rows have same height ...)
                                            bounds.X += m_syncGrid.ColWidths[0];
                                        }

                                        // If rows can have different heights:
                                        // m_syncGrid.ViewLayout.Reset();

                                        Rectangle scrollBounds         = new Rectangle(bounds.Left, bounds.Top, bounds.Right, m_syncGrid.ClientRectangle.Bottom);
                                        Rectangle scrolledInViewBounds = m_syncGrid.ScrollWindow(0, -bounds.Height, scrollBounds, scrollBounds, false);  // don't cause Invalidate being called.
                                        m_syncGrid.Model.ResetVolatileData();



                                        // DrawClippedGrid method lets you simply draw the cells at the specified bounds directly to the graphics context.
                                        if (!m_syncGrid.ViewLayout.HasPartialVisibleRows)
                                        {
                                            scrolledInViewBounds = new Rectangle(0, m_syncGrid.ViewLayout.Corner.Y, bounds.Right, bounds.Height);
                                        }

                                        m_syncGrid.DrawClippedGrid(g, scrolledInViewBounds);
                                    }

                                    m_syncGrid.UpdateScrollBars();
                                }
                            }
                        }
                    }
                }
            }
            finally
            {
            }
        }
Beispiel #19
0
        private static void OnExecuteApplyTemplateCommand(object sender, ExecutedRoutedEventArgs args)
        {
            SpreadsheetControl spreadsheetControl = args.Source as SpreadsheetControl;

            if (spreadsheetControl != null && args.Parameter != null)
            {
                IWorkbook workbook  = spreadsheetControl.ExcelProperties.WorkBook;
                string    tablename = args.Parameter.ToString();
                IRange    range     = workbook.Worksheets[0].Range["A1:E3"];
                if (tablename.Contains("Orders"))
                {
                    tablename = "Orders";
                }
                else if (tablename.Contains("Products"))
                {
                    tablename = "Products";
                }
                else if (tablename.Contains("Customers"))
                {
                    tablename = "Customers";
                }
                FillTemplate(workbook, tablename);
                DataTable DataTable = Data.GetDataTable(tablename);
                //Apply Template
                ITemplateMarkersProcessor marker = workbook.Worksheets[0].CreateTemplateMarkersProcessor();
                marker.AddVariable(tablename, DataTable, VariableTypeAction.DetectNumberFormat);
                marker.ApplyMarkers();
                if (spreadsheetControl.GridProperties.CurrentExcelGridModel != null)
                {
                    spreadsheetControl.GridProperties.CurrentExcelGridModel.InvalidateCell(GridRangeInfo.Row(1));
                }
                spreadsheetControl.GridProperties.ActiveSpreadsheetGrid.InvalidateCells();
            }
        }
Beispiel #20
0
        private void InitializeGrid()
        {
            #region CellStyleGridControl

            gridControl1.Model.Options.FloatCellsMode = GridFloatCellsMode.OnDemandCalculation;

            GridFontInfo boldFont = new GridFontInfo();
            boldFont.Bold      = true;
            boldFont.Size      = 11;
            boldFont.Underline = true;

            int rowIndex = 2;
            int colIndex = 1;

            gridControl1.Rows.DefaultSize += 2;
            int boldfontRowHeight = gridControl1.Rows.DefaultSize + 6;

            gridControl1.Model.Options.ControllerOptions         = GridControllerOptions.All;
            gridControl1.Model.Options.DataObjectConsumerOptions = GridDataObjectConsumerOptions.All;

            GridStyleInfo standard  = gridControl1.BaseStylesMap["Standard"].StyleInfo;
            GridStyleInfo header    = gridControl1.BaseStylesMap["Header"].StyleInfo;
            GridStyleInfo rowHeader = gridControl1.BaseStylesMap["Row Header"].StyleInfo;
            GridStyleInfo colHeader = gridControl1.BaseStylesMap["Column Header"].StyleInfo;

            header.Interior    = new BrushInfo(SystemColors.Control);
            rowHeader.Interior = new BrushInfo(SystemColors.Control);

            standard.Font.Facename = "Arial"; //"Helvetica";
            header.Enabled         = false;

            gridControl1.Model.Options.FloatCellsMode = GridFloatCellsMode.OnDemandCalculation;

            gridControl1.CoveredRanges.Add(GridRangeInfo.Cells(rowIndex, 1, rowIndex, 2));
            gridControl1[rowIndex, 1].Text = "Interior";
            gridControl1[rowIndex, 1].Font = boldFont;

            boldfontRowHeight = gridControl1.RowHeights[rowIndex];
            rowIndex++;

            colIndex = 1;
            foreach (Color color in new Color[] {
                Color.Black,
                Color.Red,
                Color.Blue,
                Color.Green,
                Color.Yellow,
                Color.DimGray
            })
            {
                gridControl1[rowIndex, colIndex].Interior = new BrushInfo(color);
                colIndex++;
            }
            rowIndex++;
            colIndex = 1;
            foreach (PatternStyle pattern in new PatternStyle[] {
                PatternStyle.LightVertical,
                PatternStyle.DarkDownwardDiagonal,
                PatternStyle.DashedHorizontal,
                PatternStyle.DottedDiamond,
                PatternStyle.SmallCheckerBoard,
                PatternStyle.SmallGrid
            })
            {
                gridControl1[rowIndex, colIndex].Interior = new BrushInfo(pattern, Color.Black, Color.White);
                colIndex++;
            }
            rowIndex++;
            colIndex = 1;
            foreach (GradientStyle pattern in new GradientStyle[]
            {
                GradientStyle.BackwardDiagonal,
                GradientStyle.ForwardDiagonal,
                GradientStyle.PathEllipse,
                GradientStyle.PathRectangle,
                GradientStyle.Vertical,
                GradientStyle.Horizontal
            })
            {
                gridControl1[rowIndex, colIndex].Interior           = new BrushInfo(pattern, Color.FromArgb(0xde, 0x64, 0x13), Color.Black); //Color.Yellow, Color.Blue);
                gridControl1[rowIndex, colIndex].CellAppearance     = GridCellAppearance.Raised;
                gridControl1[rowIndex + 1, colIndex].Interior       = new BrushInfo(pattern, Color.FromArgb(0x82, 0x2e, 0x1b), Color.White); //Color.Red, Color.White);
                gridControl1[rowIndex + 1, colIndex].CellAppearance = GridCellAppearance.Sunken;
                colIndex++;
            }

            rowIndex++;
            rowIndex++;
            rowIndex++;
            colIndex = 1;

            gridControl1.CoveredRanges.Add(GridRangeInfo.Cells(rowIndex, 1, rowIndex, 2));
            gridControl1[rowIndex, 1].Text    = "Font";
            gridControl1[rowIndex, 1].Font    = boldFont;
            gridControl1.RowHeights[rowIndex] = boldfontRowHeight;
            rowIndex++;

            foreach (int size in new int[] {
                6,
                7,
                8,
                10,
                12,
                14
            })
            {
                gridControl1[rowIndex, colIndex].Font.Size = size;
                gridControl1[rowIndex, colIndex].Text      = size.ToString();
                colIndex++;
            }
            gridControl1.RowHeights.ResizeToFit(GridRangeInfo.Row(rowIndex));

            rowIndex++;
            colIndex = 1;
            foreach (FontStyle fontStyle in new FontStyle[]
            {
                FontStyle.Bold,
                FontStyle.Italic,
                FontStyle.Regular,
                FontStyle.Strikeout,
                FontStyle.Underline,
                FontStyle.Bold | FontStyle.Italic | FontStyle.Regular
            })
            {
                gridControl1[rowIndex, colIndex].Font.FontStyle = fontStyle;
                gridControl1[rowIndex, colIndex].Text           = System.Enum.Format(typeof(FontStyle), fontStyle, "G");
                colIndex++;
            }

            rowIndex++;
            rowIndex++;
            colIndex = 1;

            gridControl1.CoveredRanges.Add(GridRangeInfo.Cells(rowIndex, 1, rowIndex, 2));
            gridControl1[rowIndex, 1].Text    = "TextColor";
            gridControl1[rowIndex, 1].Font    = boldFont;
            gridControl1.RowHeights[rowIndex] = boldfontRowHeight;
            rowIndex++;

            colIndex = 1;
            foreach (Color color in new Color[] {
                Color.Black,
                Color.Red,
                Color.Blue,
                Color.Green,
                Color.Yellow,
                Color.DimGray
            })
            {
                gridControl1[rowIndex, colIndex].TextColor = color;
                gridControl1[rowIndex, colIndex].Text      = ColorConvert.ColorToString(color, true);
                colIndex++;
            }

            rowIndex++;
            rowIndex++;

            gridControl1.CoveredRanges.Add(GridRangeInfo.Cells(rowIndex, 1, rowIndex, 2));
            gridControl1[rowIndex, 1].Text    = "Borders";
            gridControl1[rowIndex, 1].Font    = boldFont;
            gridControl1.RowHeights[rowIndex] = boldfontRowHeight;
            rowIndex++;
            colIndex = 1;

            foreach (GridBorder border in new GridBorder[] {
                new GridBorder(GridBorderStyle.Solid, Color.Black),
                new GridBorder(GridBorderStyle.Dotted, Color.Red),
                new GridBorder(GridBorderStyle.DashDot, Color.Black),
                new GridBorder(GridBorderStyle.DashDotDot, Color.Red),
                new GridBorder(GridBorderStyle.Dashed, Color.Black, GridBorderWeight.Medium),
                new GridBorder(GridBorderStyle.Dotted, Color.Red, GridBorderWeight.Medium)
            })
            {
                gridControl1[rowIndex, colIndex].Borders.Bottom = border;
                gridControl1[rowIndex, colIndex].Borders.Right  = border;
                gridControl1[rowIndex, colIndex].Text           = border.ToString();
                colIndex++;
            }

            rowIndex++;
            colIndex = 1;
            foreach (GridBorder border in new GridBorder[] {
                new GridBorder(GridBorderStyle.Dashed, Color.Black, GridBorderWeight.Thick),
                new GridBorder(GridBorderStyle.Dotted, Color.Red, GridBorderWeight.Thick),
                new GridBorder(GridBorderStyle.DashDot, Color.Black, GridBorderWeight.Medium),
                new GridBorder(GridBorderStyle.DashDotDot, Color.Red, GridBorderWeight.Medium),
                new GridBorder(GridBorderStyle.Solid, Color.Black, GridBorderWeight.Thick),
                new GridBorder(GridBorderStyle.Solid, Color.Red, GridBorderWeight.Medium)
            })
            {
                gridControl1[rowIndex, colIndex].Borders.Bottom = border;
                gridControl1[rowIndex, colIndex].Borders.Right  = border;
                gridControl1[rowIndex, colIndex].Text           = border.ToString();
                colIndex++;
            }

            rowIndex++;
            rowIndex++;
            colIndex = 1;

            gridControl1.CoveredRanges.Add(GridRangeInfo.Cells(rowIndex, 1, rowIndex, 2));
            gridControl1[rowIndex, 1].Text    = "Orientation";
            gridControl1[rowIndex, 1].Font    = boldFont;
            gridControl1.RowHeights[rowIndex] = boldfontRowHeight;
            rowIndex++;

            foreach (int orientation in new int[]
            {
                0,
                45,
                60,
                90,
                180,
                -90
            })
            {
                GridStyleInfo style1 = gridControl1[rowIndex, colIndex];
                // style1 is a direct reference to gridControl1[rowIndex, colIndex];
                // changes will be propagated back to GridData
                style1.HorizontalAlignment = GridHorizontalAlignment.Center;
                style1.VerticalAlignment   = GridVerticalAlignment.Middle;
                GridFontInfo font = style1.Font;
                font.Orientation = orientation;
                font.Bold        = true;
                style1.Text      = "Angle = " + font.Orientation.ToString();
                colIndex++;
            }

            gridControl1.RowHeights.ResizeToFit(GridRangeInfo.Row(rowIndex));

            rowIndex++;
            rowIndex++;
            colIndex = 1;

            gridControl1.CurrentCell.MoveTo(2, 2);

            this.gridControl1.DefaultRowHeight = 18;
            this.gridControl1.DefaultColWidth  = 70;

            this.gridControl1.DefaultGridBorderStyle = GridBorderStyle.Solid;
            #endregion

            #region StyleObject Grid
            //change the header's BackColor
            gridControl2.BaseStylesMap["Header"].StyleInfo.BackColor     = Color.FromArgb(238, 240, 246);
            gridControl2.BaseStylesMap["Row Header"].StyleInfo.BackColor = Color.FromArgb(238, 240, 246);

            //add a new basestyle
            gridBaseStyle1 = new GridBaseStyle("BackColorTest", false);
            gridControl2.BaseStylesMap["BackColorTest"].StyleInfo.BackColor = Color.SkyBlue;


            #endregion
        }
 void AssociatedObject_PrepareRenderCell(object sender, GridPrepareRenderCellEventArgs e)
 {
     if (e.Cell.RowIndex == 0 && this.AssociatedObject.Model.SelectedRanges.AnyRangeIntersects(GridRangeInfo.Col(e.Cell.ColumnIndex)))
     {
         e.Style.Background      = Brushes.LightGray;
         e.Style.Font.FontWeight = FontWeights.Bold;
     }
     else if (e.Cell.ColumnIndex == 0 && this.AssociatedObject.Model.SelectedRanges.AnyRangeIntersects(GridRangeInfo.Row(e.Cell.RowIndex)))
     {
         e.Style.Background      = Brushes.LightGray;
         e.Style.Font.FontWeight = FontWeights.Bold;
     }
 }
 void grid_PrepareRenderCell(object sender, GridPrepareRenderCellEventArgs e)
 {
     if (e.Cell.RowIndex == 0 && grid.Model.SelectedRanges.AnyRangeIntersects(GridRangeInfo.Col(e.Cell.ColumnIndex)))
     {
         e.Style.Background = this.excelOrangeColHeader;
     }
     else if (e.Cell.ColumnIndex == 0 && grid.Model.SelectedRanges.AnyRangeIntersects(GridRangeInfo.Row(e.Cell.RowIndex)))
     {
         e.Style.Background = this.excelOrangeRowHeader;
     }
     else if (inRangeSelection && selectedRange.Contains(GridRangeInfo.Cell(e.Cell.RowIndex, e.Cell.ColumnIndex)))
     {
         e.Style.Background = formulaRangeSelectionBrush;
     }
 }
        private void OnSourceListItemChanged(ListChangedEventArgs e)
        {
            //Console.WriteLine("OnSourceListItemChanged: {0} {1}", e.NewIndex, ((DataRowView)SourceList[e.NewIndex])[0]);

            int  rowIndex                 = e.NewIndex + 1;
            bool rowVisible               = IsRowVisible(rowIndex);
            bool anyCellVisible           = false;
            ChangedFieldInfoCollection cc = GetChangedFields();

            if (cc.Count > 0)
            {
                foreach (ChangedFieldInfo fi in cc)
                {
                    int columnIndex = fi.FieldIndex + 1;

                    PropertyDescriptor pd = _pdc[columnIndex - 1];
                    if (pd.PropertyType == typeof(double))
                    {
                        _totals[columnIndex - 1] += fi.Delta;
                        if (!_invalidateWholeSummaryRow)
                        {
                            InvalidateCell(new RowColumnIndex(SourceList.Count + 1, columnIndex));
                        }
                    }

                    RowColumnIndex cellRowColumnIndex = new RowColumnIndex(rowIndex, columnIndex);
                    if (CurrentCell.CellRowColumnIndex == cellRowColumnIndex)
                    {
                        if (!CurrentCell.IsInConfirmChanges)
                        {
                            CurrentCell.RejectChanges();
                            Model.VolatileCellStyles.Clear(cellRowColumnIndex);
                            RenderStyles.Clear(cellRowColumnIndex);
                            CurrentCell.Renderer.RefreshContent();
                        }
                        else
                        {
                            this.InvalidateCell(cellRowColumnIndex);
                            continue;
                        }
                    }
                    else
                    {
                        InvalidateCell(cellRowColumnIndex);
                    }
                    if (rowVisible)
                    {
                        anyCellVisible |= IsColumnVisible(columnIndex);
                    }
                }
                if (_invalidateWholeSummaryRow)
                {
                    InvalidateCell(GridRangeInfo.Row(SourceList.Count + 1));
                }
            }
            else
            {
                for (int n = 0; n < _pdc.Count; n++)
                {
                    int            columnIndex = n + 1;
                    RowColumnIndex cell        = new RowColumnIndex(rowIndex, columnIndex);
                    if (rowVisible)
                    {
                        anyCellVisible |= IsColumnVisible(columnIndex);
                    }
                }
            }
            Blink(e);
            ProcessBlinkQueue();
            if (anyCellVisible)
            {
                InvalidateVisual(false);
            }
        }
 private void InvalidateHeaders()
 {
     this.grid.InvalidateCell(GridRangeInfo.Row(0));
     this.grid.InvalidateCell(GridRangeInfo.Col(0));
 }
Beispiel #25
0
        protected override void OnPrepareRenderCell(GridPrepareRenderCellEventArgs e)
        {
            base.OnPrepareRenderCell(e);

            if (e.Cell.RowIndex == 0 && Model.SelectedRanges.AnyRangeIntersects(GridRangeInfo.Col(e.Cell.ColumnIndex)))
            {
                e.Style.Background = this.excelOrange;
            }

            else if (e.Cell.ColumnIndex == 0 && Model.SelectedRanges.AnyRangeIntersects(GridRangeInfo.Row(e.Cell.RowIndex)))
            {
                e.Style.Background = this.excelOrange;
            }
        }
Beispiel #26
0
        public static void SetupGridModel(GridModel model)
        {
            GridFactoryProvider.Init(new GridCellModelFactory());
            model.Options.AlphaBlendSelectionColor = Color.FromArgb(64, SystemColors.Highlight);
            model.Options.AllowSelection           = GridSelectionFlags.Any;

            //model.BaseStylesMap.RegisterStandardStyles();
            model.CommandStack.Enabled      = true;
            model.QueryCellModel           += new GridQueryCellModelEventHandler(ModelQueryCellModel);
            model.OperationFeedbackListener = new DelayedStatusDialog(model);

            model.BeginInit();
            model.RowCount                          = 1000;
            model.ColCount                          = 100;
            model.Rows.DefaultSize                  = 19;
            model.Cols.DefaultSize                  = 65;
            model.RowHeights[0]                     = 21;
            model.ColWidths[0]                      = 35;
            model.ColWidths[3]                      = 85;
            model.Options.ControllerOptions         = GridControllerOptions.All;
            model.Options.DataObjectConsumerOptions = GridDataObjectConsumerOptions.All;


            GridStyleInfo standard  = model.BaseStylesMap["Standard"].StyleInfo;
            GridStyleInfo header    = model.BaseStylesMap["Header"].StyleInfo;
            GridStyleInfo rowHeader = model.BaseStylesMap["Row Header"].StyleInfo;
            GridStyleInfo colHeader = model.BaseStylesMap["Column Header"].StyleInfo;

            model.Properties.GridLineColor = Color.FromArgb(65, 57, 73, 122);

            GridFontInfo boldFont = new GridFontInfo();

            boldFont.Bold     = true;
            boldFont.Size     = 11;
            boldFont.Facename = "Helvetica";

            standard.TextColor = Color.FromArgb(0, 21, 84);

            GridStyleInfo boldFontStyle = new GridStyleInfo();

            boldFontStyle.TextColor = Color.FromArgb(238, 122, 3);
            boldFontStyle.Font      = boldFont;

            header.Interior    = new BrushInfo(GradientStyle.Vertical, Color.FromArgb(65, 238, 234, 216), Color.FromArgb(65, 203, 199, 184));
            rowHeader.Interior = new BrushInfo(GradientStyle.Horizontal, Color.FromArgb(65, 238, 234, 216), Color.FromArgb(65, 203, 199, 184));

            bool showImageList = false;

            if (showImageList)
            {
                ImageList imageList = new ImageList();
                imageList.Images.Add(SystemIcons.Warning.ToBitmap());
                imageList.Images.Add(SystemIcons.Application.ToBitmap());
                imageList.Images.Add(SystemIcons.Asterisk.ToBitmap());
                imageList.Images.Add(SystemIcons.Error.ToBitmap());
                imageList.Images.Add(SystemIcons.Exclamation.ToBitmap());
                imageList.Images.Add(SystemIcons.Hand.ToBitmap());
                imageList.Images.Add(SystemIcons.Information.ToBitmap());
                imageList.Images.Add(SystemIcons.Question.ToBitmap());
                standard.ImageList = imageList;
            }

            ArrayList USStates = new ArrayList();

            USStates.Add(new USState("Alabama", "AL", 0));
            USStates.Add(new USState("Washington", "WA", 1));
            USStates.Add(new USState("West Virginia", "WV", 2));
            USStates.Add(new USState("Wisconsin", "WI", 3));
            USStates.Add(new USState("Wyoming", "WY", 4));
            USStates.Add(new USState("XAlabama", "AAL", 5));
            USStates.Add(new USState("XWashington", "AWA", 6));
            USStates.Add(new USState("XWest Virginia", "AWV", 1));
            USStates.Add(new USState("XWisconsin", "AWI", 2));
            USStates.Add(new USState("XWyoming", "AWY", 3));
            USStates.Add(new USState("QAlabama", "BAL", 4));
            USStates.Add(new USState("QWashington", "BWA", 5));
            USStates.Add(new USState("QWest Virginia", "BWV", 6));
            USStates.Add(new USState("QWisconsin", "BWI", 0));
            USStates.Add(new USState("QWyoming", "BWY", 1));

            standard.DataSource    = USStates;
            standard.DisplayMember = "LongName";
            standard.ValueMember   = "ShortName";

            Type type = typeof(Bitmap);

            System.IO.Stream stream   = typeof(SampleGrid).Module.Assembly.GetManifestResourceStream(ApplicationMain.manifestNamespace + "logo_105_65.bmp");
            Bitmap           bm       = new Bitmap(stream);
            ImageList        logoList = new ImageList();

            logoList.Images.Add(bm);
            logoList.ImageSize  = bm.Size;
            logoList.ColorDepth = ColorDepth.Depth32Bit;

            int rowIndex = 2;
            int colIndex = 1;

            int boldfontRowHeight = 0;


            model.Options.FloatCellsMode = GridFloatCellsMode.OnDemandCalculation;


            model.CoveredRanges.Add(GridRangeInfo.Cells(2, 2, 4, 4));

            model[2, 2].Text                = "Grid Demo";
            model[2, 2].Font.Bold           = true;
            model[2, 2].Font.Size           = 16;
            model[2, 2].HorizontalAlignment = GridHorizontalAlignment.Center;
            model[2, 2].VerticalAlignment   = GridVerticalAlignment.Middle;
            model[2, 2].CellType            = "Static";
            model[2, 2].Borders.All         = new GridBorder(GridBorderStyle.Solid, Color.FromArgb(65, 238, 122, 3));
            model[2, 2].Interior            = new BrushInfo(GradientStyle.PathEllipse, Color.FromArgb(65, 57, 73, 122), Color.FromArgb(65, 237, 240, 247));
            rowIndex += 5;

            model.CoveredRanges.Add(GridRangeInfo.Cells(rowIndex, 1, rowIndex, 2));
            model[rowIndex, 1].Text = "Interior";
            model.ChangeCells(GridRangeInfo.Cell(rowIndex, 1), boldFontStyle);
            model.RowHeights.ResizeToFit(GridRangeInfo.Cell(rowIndex, 1), GridResizeToFitOptions.ResizeCoveredCells | GridResizeToFitOptions.NoShrinkSize);
            boldfontRowHeight = model.RowHeights[rowIndex];
            rowIndex++;

            colIndex = 1;
            foreach (int index in new int[] {
                1,
                2,
                3,
                4,
                5,
                6,
            })
            {
                model[rowIndex, colIndex].ImageIndex = index;
                colIndex++;
            }
            rowIndex++;


            colIndex = 1;
            foreach (Color color1 in new Color[] {
                Color.FromArgb(65, 0, 0, 51),
                Color.FromArgb(65, 252, 172, 38),
                Color.FromArgb(65, 33, 67, 126),
                Color.FromArgb(65, 102, 110, 152),
                Color.FromArgb(65, 204, 212, 230),
                Color.FromArgb(65, 237, 240, 247),
            })
            {
                model[rowIndex, colIndex].Interior = new BrushInfo(color1);
                colIndex++;
            }

            rowIndex++;
            colIndex = 1;
            foreach (PatternStyle pattern in new PatternStyle[]
            {
                PatternStyle.Percent05,
                PatternStyle.Percent20,
                PatternStyle.Percent50,
                PatternStyle.Percent75,
                PatternStyle.DarkDownwardDiagonal,
                PatternStyle.LightDownwardDiagonal
            })
            {
                model[rowIndex, colIndex].Interior = new BrushInfo(pattern, Color.FromArgb(65, 237, 240, 247), Color.FromArgb(65, 57, 73, 122));
                colIndex++;
            }

            rowIndex++;
            colIndex = 1;
            foreach (GradientStyle gradient in new GradientStyle[]
            {
                GradientStyle.BackwardDiagonal,
                GradientStyle.ForwardDiagonal,
                GradientStyle.PathEllipse,
                GradientStyle.PathRectangle,
                GradientStyle.Vertical,
                GradientStyle.Horizontal,
            })
            {
                model[rowIndex, colIndex].Interior     = new BrushInfo(gradient, Color.FromArgb(65, 57, 73, 122), Color.FromArgb(65, 237, 240, 247));
                model[rowIndex + 1, colIndex].Interior = new BrushInfo(gradient, Color.FromArgb(65, 237, 240, 247), Color.FromArgb(65, 51, 51, 102));
                colIndex++;
            }

            rowIndex++;
            rowIndex++;
            rowIndex++;
            colIndex = 1;

            model.CoveredRanges.Add(GridRangeInfo.Cells(rowIndex, 1, rowIndex, 2));
            model[rowIndex, 1].Text = "Font";
            model.ChangeCells(GridRangeInfo.Cell(rowIndex, 1), boldFontStyle);
            model.RowHeights[rowIndex] = boldfontRowHeight;
            rowIndex++;

            foreach (int size in new int[]
            {
                6,
                7,
                8,
                10,
                12,
                14
            })
            {
                model[rowIndex, colIndex].Font.Size = size;
                model[rowIndex, colIndex].Text      = size.ToString();
                colIndex++;
            }
            model.RowHeights.ResizeToFit(GridRangeInfo.Row(rowIndex), GridResizeToFitOptions.ResizeCoveredCells | GridResizeToFitOptions.NoShrinkSize);

            rowIndex++;
            colIndex = 1;
            foreach (FontStyle fontStyle in new FontStyle[]
            {
                FontStyle.Bold,
                FontStyle.Italic,
                FontStyle.Regular,
                FontStyle.Strikeout,
                FontStyle.Underline,
                FontStyle.Bold | FontStyle.Italic | FontStyle.Regular,
            })
            {
                model[rowIndex, colIndex].Font.FontStyle = fontStyle;
                model[rowIndex, colIndex].Text           = Enum.Format(typeof(FontStyle), fontStyle, "G");
                colIndex++;
            }

            rowIndex++;
            rowIndex++;
            colIndex = 1;

            model.CoveredRanges.Add(GridRangeInfo.Cells(rowIndex, 1, rowIndex, 2));
            model[rowIndex, 1].Text = "TextColor";
            model.ChangeCells(GridRangeInfo.Cell(rowIndex, 1), boldFontStyle);
            model.RowHeights[rowIndex] = boldfontRowHeight;
            rowIndex++;

            colIndex = 1;
            foreach (Color color2 in new Color[] {
                Color.Black,
                Color.Red,
                Color.Blue,
                Color.Green,
                Color.Yellow,
                Color.DimGray
            })
            {
                model[rowIndex, colIndex].TextColor = color2;
                model[rowIndex, colIndex].Text      = ColorConvert.ColorToString(color2, true);
                colIndex++;
            }

            rowIndex++;
            rowIndex++;

            colIndex = 1;

            model.CoveredRanges.Add(GridRangeInfo.Cells(rowIndex, 1, rowIndex, 2));
            model[rowIndex, 1].Text = "Number Formats";
            model.ChangeCells(GridRangeInfo.Cell(rowIndex, 1), boldFontStyle);
            model.RowHeights[rowIndex] = boldfontRowHeight;
            rowIndex++;

            colIndex = 1;
            foreach (string format2 in new string[]
            {
                "0.00",
                "C",
                "0.00;(0.00)",
                "###0.##%",
                "#0.#E+00",
                "10:##,##0.#"
            })
            {
                model[rowIndex, colIndex].Format        = format2;
                model[rowIndex, colIndex].CellValue     = Math.PI;
                model[rowIndex, colIndex].CellValueType = typeof(double);
                colIndex++;
            }

            rowIndex++;
            rowIndex++;

            colIndex = 1;

            model.CoveredRanges.Add(GridRangeInfo.Cells(rowIndex, 1, rowIndex, 2));
            model[rowIndex, 1].Text = "DateTime Formats";
            model.ChangeCells(GridRangeInfo.Cell(rowIndex, 1), boldFontStyle);
            model.RowHeights[rowIndex] = boldfontRowHeight;
            rowIndex++;

            colIndex = 1;
            foreach (string format in new string[]
            {
                "d",
                "D",
                "f",
                "dddd, dd MMMM yyyy",
                "t",
                "s"
            })
            {
                model[rowIndex, colIndex].Format        = format;
                model[rowIndex, colIndex].CellValue     = DateTime.Now;
                model[rowIndex, colIndex].CellValueType = typeof(DateTime);
                colIndex++;
            }

            rowIndex++;
            rowIndex++;

            model.CoveredRanges.Add(GridRangeInfo.Cells(rowIndex, 1, rowIndex, 2));
            model[rowIndex, 1].Text = "Validation";
            model.ChangeCells(GridRangeInfo.Cell(rowIndex, 1), boldFontStyle);
            model.RowHeights[rowIndex] = boldfontRowHeight;
            rowIndex++;

            model[rowIndex, 1].Text = "Positive numbers";
            model.RowStyles[rowIndex].ValidateValue.NumberRequired = true;
            model.RowStyles[rowIndex].ValidateValue.Minimum        = 0;
            model.RowStyles[rowIndex].ValidateValue.Maximum        = float.NaN;
            model.RowStyles[rowIndex].ValidateValue.ErrorMessage   = "Please enter a number greater than 0!";
            rowIndex++;

            model[rowIndex, 1].Text = "Validation (1-100 valid range)";
            model.RowStyles[rowIndex].ValidateValue = new GridCellValidateValueInfo(true, 1, 100, "Please enter a number between 1 and 100!");
            rowIndex++;
            rowIndex++;

            model.CoveredRanges.Add(GridRangeInfo.Cells(rowIndex, 1, rowIndex, 2));
            model[rowIndex, 1].Text = "Cell Types";
            model.ChangeCells(GridRangeInfo.Cell(rowIndex, 1), boldFontStyle);
            model.RowHeights[rowIndex] = boldfontRowHeight;
            rowIndex++;

            colIndex = 1;

            model.TableStyle.CheckBoxOptions     = new GridCheckBoxCellInfo("True", "False", "", false);
            model[rowIndex, 1].Text              = "CheckBox";
            model[rowIndex, 3].CellType          = "CheckBox";
            model[rowIndex, 3].TriState          = false;
            model[rowIndex, 3].Text              = "True";
            model[rowIndex, 3].VerticalAlignment = GridVerticalAlignment.Middle;
            model[rowIndex, 3].Description       = "Enabled";
            model[rowIndex, 4].CellType          = "CheckBox";
            model[rowIndex, 4].Text              = "False";
            model[rowIndex, 4].Enabled           = false;
            model[rowIndex, 4].Description       = "Disabled";
            model[rowIndex, 4].VerticalAlignment = GridVerticalAlignment.Middle;
            model[rowIndex, 5].CellType          = "CheckBox";
            model[rowIndex, 5].TriState          = true;
            model[rowIndex, 5].Description       = "TriState";
            model[rowIndex, 5].VerticalAlignment = GridVerticalAlignment.Middle;
            rowIndex++;

            rowIndex++;
            rowIndex++;

            model[rowIndex, 1].Text     = "DragButton";
            model[rowIndex, 3].Text     = "Drag";
            model[rowIndex, 3].CellType = "DragButton";
            rowIndex++;

            model.TableStyle.NumericUpDown = new GridNumericUpDownCellInfo(0, 25, 1, 1, true);
            model[rowIndex, 1].Text        = "NumericUpDown";
            // Wrapping, Range 0-1000
            model[rowIndex, 3].CellType      = "NumericUpDown";
            model[rowIndex, 3].NumericUpDown = new GridNumericUpDownCellInfo(0, 1000, 0, 1, true);
            // Disabled
            model[rowIndex, 4].CellType = "NumericUpDown";
            model[rowIndex, 4].Enabled  = false;
            model[rowIndex, 4].Text     = "5";
            // No wrapping, Range 1-20
            model[rowIndex, 5].CellType      = "NumericUpDown";
            model[rowIndex, 5].NumericUpDown = new GridNumericUpDownCellInfo(1, 20, 1, 1, false);
            rowIndex++;

            model[rowIndex, 1].Text        = "PushButton";
            model[rowIndex, 3].CellType    = "PushButton";
            model[rowIndex, 3].Description = "Enabled";
            model[rowIndex, 4].CellType    = "PushButton";
            model[rowIndex, 4].Enabled     = false;
            model[rowIndex, 4].Clickable   = false;
            model[rowIndex, 4].Description = "Disabled";
            rowIndex++;

            StringCollection items = new StringCollection();

            items.Add("One");
            items.Add("Two");
            items.Add("Three");
            items.Add("Four");
            items.Add("Five");
            items.Add("Six");
            items.Add("Seven");
            items.Add("Eight");
            items.Add("Nine");
            items.Add("Ten");

            model[rowIndex, 1].Text = "ComboBox (Edit)";

            model[rowIndex, 3].CellType   = "ComboBox";
            model[rowIndex, 3].ChoiceList = items;
            // Disabled
            model[rowIndex, 4].CellType   = "ComboBox";
            model[rowIndex, 4].ChoiceList = items;
            model[rowIndex, 4].Enabled    = false;
            model[rowIndex, 4].CellValue  = items[5];
            rowIndex++;

            model[rowIndex, 1].Text = "ComboBox (List)";

            model[rowIndex, 3].CellType            = "ComboBox";
            model[rowIndex, 3].ChoiceList          = items;
            model[rowIndex, 3].ExclusiveChoiceList = true;              // tell combobox to behave like CBS_DROPDOWNSTYLE
            // Disabled
            model[rowIndex, 4].CellType            = "ComboBox";
            model[rowIndex, 4].ChoiceList          = items;
            model[rowIndex, 4].Enabled             = false;
            model[rowIndex, 4].ExclusiveChoiceList = true;              // tell combobox to behave like CBS_DROPDOWNSTYLE
            model[rowIndex, 4].CellValue           = items[5];
            rowIndex++;
            rowIndex++;

            model[rowIndex, 1].Text       = "GridListControl (Edit)";
            model[rowIndex, 3].CellType   = "GridListControl";
            model[rowIndex, 3].DataSource = USStates;

            // Disabled
            model[rowIndex, 4].CellType   = "GridListControl";
            model[rowIndex, 4].DataSource = USStates;
            rowIndex++;

            model[rowIndex, 1].Text = "GridListControl (List)";

            model[rowIndex, 3].CellType            = "GridListControl";
            model[rowIndex, 3].DataSource          = USStates;
            model[rowIndex, 3].ExclusiveChoiceList = true;              // tell combobox to behave like CBS_DROPDOWNSTYLE
            rowIndex++;
            rowIndex++;


            model.CoveredRanges.Add(GridRangeInfo.Cells(rowIndex, 1, rowIndex, 2));
            model[rowIndex, 1].Text = "DropDown Cells";
            model.ChangeCells(GridRangeInfo.Cell(rowIndex, 1), boldFontStyle);
            model.RowHeights[rowIndex] = boldfontRowHeight;
            rowIndex++;

            //
            model[rowIndex, 1].Text     = "Generic DropDown";
            model[rowIndex, 3].CellType = "DropDown";
            rowIndex++;

            model[rowIndex, 1].Text     = "MonthCalendar";
            model[rowIndex, 3].CellType = "MonthCalendar";
            rowIndex++;

            model[rowIndex, 1].Text     = "ColorEdit";
            model[rowIndex, 3].CellType = "ColorEdit";
            rowIndex++;

            model[rowIndex, 1].Text     = "DropDownGrid";
            model[rowIndex, 3].CellType = "DropDownGrid";
            rowIndex++;
            rowIndex++;

            colIndex = 1;

            model.CoveredRanges.Add(GridRangeInfo.Cells(rowIndex, 1, rowIndex, 2));
            model[rowIndex, 1].Text = "Borders";
            model.ChangeCells(GridRangeInfo.Cell(rowIndex, 1), boldFontStyle);
            model.RowHeights[rowIndex] = boldfontRowHeight;
            rowIndex++;

            foreach (GridBorder border2 in new GridBorder[] {
                new GridBorder(GridBorderStyle.Solid, Color.FromArgb(57, 73, 122)),
                new GridBorder(GridBorderStyle.Dotted, Color.FromArgb(238, 122, 3)),
                new GridBorder(GridBorderStyle.DashDot, Color.FromArgb(57, 73, 122)),
                new GridBorder(GridBorderStyle.DashDotDot, Color.FromArgb(238, 122, 3)),
                new GridBorder(GridBorderStyle.Dashed, Color.FromArgb(57, 73, 122), GridBorderWeight.Medium),
                new GridBorder(GridBorderStyle.Dotted, Color.FromArgb(238, 122, 3), GridBorderWeight.Medium),
            })
            {
                model[rowIndex, colIndex].Borders.Bottom = border2;
                model[rowIndex, colIndex].Borders.Right  = border2;
                model[rowIndex, colIndex].Text           = border2.ToString();
                colIndex++;
            }

            rowIndex++;
            colIndex = 1;
            foreach (GridBorder border in new GridBorder[] {
                new GridBorder(GridBorderStyle.Dashed, Color.FromArgb(57, 73, 122), GridBorderWeight.Thick),
                new GridBorder(GridBorderStyle.Dotted, Color.FromArgb(238, 122, 3), GridBorderWeight.Thick),
                new GridBorder(GridBorderStyle.DashDot, Color.FromArgb(57, 73, 122), GridBorderWeight.Medium),
                new GridBorder(GridBorderStyle.DashDotDot, Color.FromArgb(238, 122, 3), GridBorderWeight.Medium),
                new GridBorder(GridBorderStyle.Solid, Color.FromArgb(57, 73, 122), GridBorderWeight.Thick),
                new GridBorder(GridBorderStyle.Solid, Color.FromArgb(238, 122, 3), GridBorderWeight.Medium),
            })
            {
                model[rowIndex, colIndex].Borders.Bottom = border;
                model[rowIndex, colIndex].Borders.Right  = border;
                model[rowIndex, colIndex].Text           = border.ToString();
                colIndex++;
            }

            rowIndex++;
            rowIndex++;
            colIndex = 1;

            model.CoveredRanges.Add(GridRangeInfo.Cells(rowIndex, 1, rowIndex, 2));
            model[rowIndex, 1].Text = "Orientation";
            model[rowIndex, 1].ModifyStyle(boldFontStyle, StyleModifyType.Override);
            model.RowHeights[rowIndex] = boldfontRowHeight;
            rowIndex++;

            foreach (int orientation in new int[]
            {
                0,
                45,
                60,
                90,
                180,
                -90
            })
            {
                GridStyleInfo style1 = model[rowIndex, colIndex];
                // style1 is a direct reference to model[rowIndex, colIndex];
                // changes will be propagated back to GridData
                style1.HorizontalAlignment = GridHorizontalAlignment.Center;
                style1.VerticalAlignment   = GridVerticalAlignment.Middle;
                GridFontInfo font = style1.Font;
                font.Orientation = orientation;
                font.Bold        = true;
                style1.Text      = "Angle = " + font.Orientation.ToString();
                colIndex++;
            }

            rowIndex++;
            rowIndex++;
            colIndex = 1;

            model.CoveredRanges.Add(GridRangeInfo.Cells(rowIndex, 1, rowIndex, 2));
            model[rowIndex, 1].Text = "Enabled";
            model[rowIndex, 1].ModifyStyle(boldFontStyle, StyleModifyType.Override);
            model.RowHeights[rowIndex] = boldfontRowHeight;
            rowIndex++;

            foreach (bool enabled1 in new bool[]
            {
                true,
                false,
                true,
                false,
                false,
                true,
            })
            {
                model[rowIndex, colIndex].Text     = enabled1?"YES":"NO";
                model[rowIndex, colIndex].Interior = new BrushInfo((Color)(enabled1?Color.FromArgb(65, 57, 73, 122):Color.FromArgb(65, 238, 122, 3)));
                model[rowIndex, colIndex].Enabled  = enabled1;
                colIndex++;
            }

            colIndex = 1;
            rowIndex++;

            foreach (bool enabled2 in new bool[]
            {
                true,
                true,
                false,
                false,
                false,
                true,
            })
            {
                model[rowIndex, colIndex].Text     = enabled2?"YES":"NO";
                model[rowIndex, colIndex].Interior = new BrushInfo((Color)(enabled2?Color.FromArgb(65, 57, 73, 122):Color.FromArgb(65, 238, 122, 3)));
                model[rowIndex, colIndex].Enabled  = enabled2;
                colIndex++;
            }

            rowIndex++;
            rowIndex++;
            colIndex = 1;

            model.CoveredRanges.Add(GridRangeInfo.Cells(rowIndex, 1, rowIndex, 2));
            model[rowIndex, 1].Text = "AutoSize";
            model[rowIndex, 1].ModifyStyle(boldFontStyle, StyleModifyType.Override);
            model.RowHeights[rowIndex] = boldfontRowHeight;
            rowIndex++;

            model.RowStyles[rowIndex].AutoSize = true;
            model.RowStyles[rowIndex].Text     = "Row height will increase while you type text";
            model.RowStyles[rowIndex].Interior = new BrushInfo(Color.Beige);

            rowIndex++;
            rowIndex++;
            colIndex = 1;

            model.CoveredRanges.Add(GridRangeInfo.Cells(rowIndex, 1, rowIndex, 2));
            model[rowIndex, 1].Text = "Read Only";
            model[rowIndex, 1].ModifyStyle(boldFontStyle, StyleModifyType.Override);
            model.RowHeights[rowIndex] = boldfontRowHeight;
            rowIndex++;

            model.RowStyles[rowIndex].ReadOnly = true;
            model.RowStyles[rowIndex].Interior = new BrushInfo(Color.LightGray);
            model.RowStyles[rowIndex].Text     = "ReadOnly";
            rowIndex++;
            rowIndex++;


            model.Options.ExcelLikeCurrentCell        = false;
            model.Options.ExcelLikeSelectionFrame     = false;
            model.Options.ActivateCurrentCellBehavior = GridCellActivateAction.ClickOnCell;
            model.Properties.MarkColHeader            = true;
            model.Properties.MarkRowHeader            = true;

            model.RowHeights.ResizeToFit(GridRangeInfo.Cells(2, 1, rowIndex, 3), GridResizeToFitOptions.ResizeCoveredCells | GridResizeToFitOptions.NoShrinkSize);
            model.EndInit();
        }
Beispiel #27
0
        /// <summary>
        /// Data table imported to the workbook by using the template marker support
        /// </summary>
        /// <param name="workbook">Workbook</param>
        /// <param name="tablename">Data Table name</param>
        private void ApplyTemplate(IWorkbook workbook, string tablename)
        {
            IRange range = workbook.Worksheets[0].Range["A1:E3"];

            if (tablename.Contains("Orders"))
            {
                tablename = "Orders";
            }
            else if (tablename.Contains("Products"))
            {
                tablename = "Products";
            }
            else if (tablename.Contains("Customers"))
            {
                tablename = "Customers";
            }
            FillTemplate(workbook, tablename);
            DataTable DataTable = Data.GetDataTable(tablename);
            //Apply Template
            ITemplateMarkersProcessor marker = workbook.Worksheets[0].CreateTemplateMarkersProcessor();

            marker.AddVariable(tablename, DataTable, VariableTypeAction.DetectNumberFormat);
            marker.ApplyMarkers();
            if (this.AssociatedObject.GridProperties.CurrentExcelGridModel != null)
            {
                this.AssociatedObject.GridProperties.CurrentExcelGridModel.InvalidateCell(GridRangeInfo.Row(1));
            }
        }