Beispiel #1
0
 // gif image customization
 void t_Tick(object sender, EventArgs e)
 {
     if (this.gridGroupingControl1.TableControl.CurrentCell != null)
     {
         this.gridGroupingControl1.TableControl.RefreshRange(GridRangeInfo.Col(2));
     }
 }
        /// <summary>
        /// Does some low level initializations. Generally, you should use the WireSelfReferenceGrid method which, in turn, will
        /// call WireGrid.
        /// </summary>
        /// <param name="grid">The GridDataBoundGrid</param>
        /// <param name="parentList">The parentList</param>
        /// <param name="dataSource">The dataSource that serves as an ITreeGridDataSource.</param>
        public void WireGrid(GridGroupingControl grid, IList parentList, ITreeGridDataSource dataSource)
        {
            this.grid = grid;
            this.grid.TableControl.BeginUpdate();

            //used by renderer to access rowindexer
            this.grid.TableControl.Model.TableStyle.Tag = this;

            this.dataSource = dataSource;

            if (!this.grid.TableControl.Model.CellModels.ContainsKey("GridTreeCell"))
            {
                this.grid.TableControl.Model.CellModels.Add("GridTreeCell", new GridDataBoundTreeCellModel(this.grid.TableControl.Model, this));
            }

            this.grid.TableDescriptor.Columns[nodeProperty].Appearance.AnyRecordFieldCell.CellType = "GridTreeCell";

            WireTreeLineEvents();


            rowIndexer.Clear();
            PopulateIndexer(0, parentList, 0);
            this.grid.TableControl.Model.ResetVolatileData();

            this.grid.TableControl.Model.ColWidths.ResizeToFit(GridRangeInfo.Col(2));

            this.grid.TableControl.EndUpdate();

            this.grid.TableControl.Refresh();
        }
        private void DrawColumnLines(PaintEventArgs pe)
        {
            if (PageBreakCols.Count > 0)
            {
                foreach (int col in PageBreakCols)
                {
                    if (col > grid.ViewLayout.LastVisibleCol ||
                        (col == grid.ViewLayout.LastVisibleCol && grid.ViewLayout.HasPartialVisibleCols))
                    {
                        break;
                    }
                    if (col < grid.LeftColIndex)
                    {
                        continue;
                    }

                    Rectangle rect = grid.RangeInfoToRectangle(GridRangeInfo.Col(col));

                    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.Right, rect.Top, rect.Right, rect.Bottom);
                        pe.Graphics.Clip = region;
                    }
                }
            }
        }
Beispiel #4
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);
                }
            }
        }
 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;
     }
 }
 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));
     }
 }
Beispiel #7
0
        void ColumnWidths_LineSizeChanged(object sender, RangeChangedEventArgs e)
        {
            double width = this.ColumnWidths[e.From];

            if (width == 0)
            {
                foreach (GridRangeInfo range in this.Model.SelectedRanges)
                {
                    GridRangeInfo intersect = range.IntersectRange(GridRangeInfo.Col(e.From));
                    for (int row = intersect.Top; row <= intersect.Bottom; row++)
                    {
                        for (int col = intersect.Left; col <= intersect.Right; col++)
                        {
                            if (col + 1 != this.Model.ColumnCount)
                            {
                                this.Model[row, col + 1].Borders.Left = new Pen(Brushes.Black, 2);
                            }
                            else
                            {
                                this.Model[row, col - 1].Borders.Right = new Pen(Brushes.Black, 2);
                            }
                        }
                    }
                }
                this.Model.InvalidateVisual(true);
            }
            else
            {
                foreach (GridRangeInfo range in this.Model.SelectedRanges)
                {
                    GridRangeInfo intersect = range.IntersectRange(GridRangeInfo.Col(e.From));
                    double        w         = this.Model.ColumnWidths[intersect.Left];
                    if (w == 0)
                    {
                        return;
                    }
                    for (int row = intersect.Top; row <= intersect.Bottom; row++)
                    {
                        for (int col = intersect.Left; col <= intersect.Right; col++)
                        {
                            if (col + 1 != this.Model.ColumnCount)
                            {
                                this.Model[row, col + 1].Borders.Left = null;
                            }
                            else
                            {
                                this.Model[row, col - 1].Borders.Right = null;
                            }
                        }
                    }
                }
                this.Model.InvalidateVisual(true);
            }
        }
        /// <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 OnSourceListPropertyDescriptorChanged(ListChangedEventArgs e)
        {
            _pdc = ListUtil.GetItemProperties(SourceList);
            int field       = _pdc.IndexOf(e.PropertyDescriptor);
            int columnIndex = field + 1;

            InvalidateCell(GridRangeInfo.Col(columnIndex));
            InvalidateCell(new RowColumnIndex(SourceList.Count + 1, columnIndex));
            if (IsColumnVisible(columnIndex))
            {
                InvalidateVisual(false);
            }
        }
Beispiel #10
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 #11
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;
            }
        }
 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;
     }
 }
        /// <summary>
        /// Disconnects this TreeHelper from its GridDataBoundGrid.
        /// </summary>
        public void UnwireGrid()
        {
            if (this.grid.TableControl != null)
            {
                this.grid.TableControl.BeginUpdate();
                this.grid.TableControl.Model.TableStyle.Tag = null;
                UnwireTreeLineEvents();

                this.grid.TableControl.Model.ColWidths.ResizeToFit(GridRangeInfo.Col(TREECOLUMN));
                this.grid.TableControl.EndUpdate();
                this.grid.TableControl.Refresh();

                this.grid = null;
            }
        }
        /// <summary>
        /// Expands all nodes in the wired grid.
        /// </summary>
        public void ExpandAll()
        {
            this.grid.TableControl.Parent.Cursor = Cursors.WaitCursor;
            this.grid.TableControl.BeginUpdate();
            this.CollapseAll(); //speeds things up...
            int rowIndex = rowOffSet;

            while (rowIndex <= this.grid.TableControl.Model.RowCount)
            {
                ExpandNode(rowIndex, false, false);
                rowIndex += 1;
            }
            this.grid.TableControl.Model.ColWidths.ResizeToFit(GridRangeInfo.Col(TREECOLUMN), GridResizeToFitOptions.NoShrinkSize);
            this.grid.TableControl.EndUpdate();
            this.grid.TableControl.Parent.Cursor = Cursors.Default;
            this.grid.TableControl.Refresh();
        }
Beispiel #15
0
        //FindAll - Loops through the cells in the grid and highlights all the values
        //that match with the given search string.
        private void btnFindAll_Click(object sender, EventArgs e)
        {
            if (cmbSearch.Text != null)
            {
                AddToSearchedList(cmbSearch.Text);

                SetOptions();
                locInfo = GridRangeInfo.Table();
                GridRangeInfo selRange = GridRangeInfo.Empty;
                int           rowIndex, colIndex;
                if ((options & GridFindTextOptions.SelectionOnly) != GridFindTextOptions.None)
                {
                    selRange = gridControl1.Selections.Ranges.ActiveRange;
                }

                else if ((options & GridFindTextOptions.ColumnOnly) != GridFindTextOptions.None)
                {
                    selRange = GridRangeInfo.Col(gridControl1.CurrentCell.ColIndex);
                }

                else if ((options & GridFindTextOptions.WholeTable) != GridFindTextOptions.None)
                {
                    selRange = GridRangeInfo.Cells(1, 1, gridControl1.RowCount, gridControl1.ColCount);
                }

                clearHighlight();

                int startTop  = selRange.Top;
                int startLeft = selRange.Left;

                do
                {
                    GridStyleInfo        style    = gridControl1[startTop, startLeft];
                    GridCellRendererBase renderer = gridControl1.CellRenderers[style.CellType];
                    if (renderer.FindText(cmbSearch.Text, startTop, startLeft, options, true))
                    {
                        gridControl1.CurrentCell.GetCurrentCell(out rowIndex, out colIndex);
                        gridControl1[rowIndex, colIndex].BackColor = Color.Orange;
                    }
                } while (GridFindReplaceDialogSink.GetNextCell(selRange, ref startTop, ref startLeft, false, chkSearchUp.Checked));
            }
            this.highlighttext.HighlightText = "";
            this.gridControl1.Refresh();
            this.checkBox1.CheckState = CheckState.Unchecked;
        }
Beispiel #16
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));
        }
        protected override void OnButtonClicked(int rowIndex, int colIndex, int button)
        {
            base.OnButtonClicked(rowIndex, colIndex, button);

            try
            {
                string s = Grid.Model[rowIndex, colIndex].Text;
                InitDialog(s);

                if (_dialog.ShowDialog() == DialogResult.OK)
                {
                    Grid.Model[rowIndex, colIndex].Text = _dialog.FileName;
                }

                Grid.Model.ColWidths.ResizeToFit(GridRangeInfo.Col(colIndex), GridResizeToFitOptions.None);
            }
            catch (Exception ex)
            {
                Logger.Current.Warn("OpenFileDialogCellRenderer: failed to edit datasource path.", ex);
            }
        }
 private void InvalidateHeaders()
 {
     this.grid.InvalidateCell(GridRangeInfo.Row(0));
     this.grid.InvalidateCell(GridRangeInfo.Col(0));
 }
Beispiel #19
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 #20
0
        public Form1()
        {
            //
            // Required for Windows Form Designer support
            //
            InitializeComponent();

            #region Custom Cells
            gridControl1.DefaultRowHeight        = 22;
            gridControl1.ExcelLikeCurrentCell    = true;
            gridControl1.ExcelLikeSelectionFrame = true;
            gridControl1.ControllerOptions       = GridControllerOptions.All;
            gridControl1.HScrollBehavior         = GridScrollbarMode.Disabled;
            gridControl1.CoveredRanges.Add(GridRangeInfo.Cells(1, 1, 2, gridControl1.ColCount));
            gridControl1[1, 1].Text                = "Derived Cell Controls";
            gridControl1[1, 1].Font.Bold           = true;
            gridControl1[1, 1].Font.Size           = 12;
            gridControl1[1, 1].TextColor           = Color.Black;
            gridControl1[1, 1].CellType            = GridCellTypeName.Static;
            gridControl1[1, 1].VerticalAlignment   = GridVerticalAlignment.Middle;
            gridControl1[1, 1].HorizontalAlignment = GridHorizontalAlignment.Center;
            gridControl1.CellModels.Add("LinkLabelCell", new LinkLabelCellModel(gridControl1.Model));

            int rowIndex = 4;
            gridControl1[rowIndex, 4].Text                = "Syncfusion, Inc.";
            gridControl1[rowIndex, 4].Font.Bold           = true;
            gridControl1[rowIndex, 4].Tag                 = "http://www.syncfusion.com";
            gridControl1[rowIndex, 4].HorizontalAlignment = GridHorizontalAlignment.Center;
            gridControl1[rowIndex, 4].CellType            = "LinkLabelCell";

            rowIndex++;
            gridControl1[rowIndex, 4].CellType            = "LinkLabelCell";
            gridControl1[rowIndex, 4].Text                = "Windows Forms FAQ";
            gridControl1[rowIndex, 4].Font.Bold           = true;
            gridControl1[rowIndex, 4].Tag                 = "http://www.syncfusion.com/support/forums/grid-windows";
            gridControl1[rowIndex, 4].HorizontalAlignment = GridHorizontalAlignment.Center;

            rowIndex++;
            gridControl1[rowIndex, 4].CellType            = "LinkLabelCell";
            gridControl1[rowIndex, 4].Text                = "Microsoft Windows Forms";
            gridControl1[rowIndex, 4].Font.Bold           = true;
            gridControl1[rowIndex, 4].Tag                 = "http://windowsforms.net/";
            gridControl1[rowIndex, 4].HorizontalAlignment = GridHorizontalAlignment.Center;

            rowIndex++;
            gridControl1[rowIndex, 4].CellType            = "LinkLabelCell";
            gridControl1[rowIndex, 4].Text                = "MSDN";
            gridControl1[rowIndex, 4].Font.Bold           = true;
            gridControl1[rowIndex, 4].Tag                 = "http://msdn.microsoft.com";
            gridControl1[rowIndex, 4].HorizontalAlignment = GridHorizontalAlignment.Center;

            rowIndex++;
            gridControl1[rowIndex, 4].CellType            = "LinkLabelCell";
            gridControl1[rowIndex, 4].Text                = "Yahoo";
            gridControl1[rowIndex, 4].Font.Bold           = true;
            gridControl1[rowIndex, 4].Tag                 = "http://www.yahoo.com";
            gridControl1[rowIndex, 4].HorizontalAlignment = GridHorizontalAlignment.Center;

            rowIndex++;
            gridControl1[rowIndex, 4].CellType            = "LinkLabelCell";
            gridControl1[rowIndex, 4].Text                = "Google";
            gridControl1[rowIndex, 4].Font.Bold           = true;
            gridControl1[rowIndex, 4].Tag                 = "http://www.google.com/";
            gridControl1[rowIndex, 4].HorizontalAlignment = GridHorizontalAlignment.Center;

            gridControl1.ColWidths.ResizeToFit(GridRangeInfo.Col(4));
            gridControl1.ColStyles[4].TextColor = Color.Blue;

            this.gridControl1.DefaultColWidth                = 70;
            this.gridControl1.DefaultGridBorderStyle         = GridBorderStyle.Solid;
            gridControl1.AllowProportionalColumnSizing       = true;
            this.gridControl1.Model.Options.DisplayEmptyRows = true;
            this.gridControl1.RowHeights[0] = 30;

            #endregion
        }
Beispiel #21
0
        private void InitializeGrid()
        {
            #region Style prerequistes
            GridStyleInfo standard = gridControl1.BaseStylesMap["Standard"].StyleInfo;
            standard.Font.Bold     = false;
            standard.Font.Facename = "Verdana"; //"Verdana";
            standard.Font.Size     = 10;
            standard.TextColor     = Color.FromArgb(240, 0, 21, 84);
            gridControl1.Font      = new System.Drawing.Font("Verdana", 8.5F);


            // grab some images...
            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;

            Icon icon = new Icon(GetType().Module.Assembly.GetManifestResourceStream("EditorCellDemo.gridform.ico"));
            imageList.Images.Add(icon.ToBitmap());

            icon = new Icon(GetType().Module.Assembly.GetManifestResourceStream("EditorCellDemo.toolsform.ico"));
            imageList.Images.Add(icon.ToBitmap());
            standard.ImageList = imageList;

            #endregion

            #region Codes to apply celltypes in Grid
            this.gridControl1.BeginUpdate();
            gridControl1.TableStyle.FloatCell = true;
            gridControl1.FloatCellsMode       = GridFloatCellsMode.BeforeDisplayCalculation;

            #region Style declaration
            GridStyleInfo headerstyle = new GridStyleInfo();
            headerstyle.Font.Size           = 12;
            headerstyle.Font.Bold           = true;
            headerstyle.VerticalAlignment   = GridVerticalAlignment.Middle;
            headerstyle.HorizontalAlignment = GridHorizontalAlignment.Center;
            headerstyle.CellType            = GridCellTypeName.Static;

            GridStyleInfo subheaderstyle = new GridStyleInfo();
            subheaderstyle.Font.Bold           = true;
            subheaderstyle.VerticalAlignment   = GridVerticalAlignment.Middle;
            subheaderstyle.HorizontalAlignment = GridHorizontalAlignment.Center;
            subheaderstyle.CellType            = GridCellTypeName.Static;
            subheaderstyle.TextColor           = Color.Gray;

            gridControl1.Model.ColWidths[4] = 90;
            gridControl1.Model.ColWidths[6] = 100;
            #endregion

            #region TextBox Cells
            gridControl1.CoveredRanges.Add(GridRangeInfo.Cells(1, 1, 2, gridControl1.ColCount));
            gridControl1[1, 1]      = headerstyle;
            gridControl1[1, 1].Text = "TextBox Cells";

            int rowIndex = 3, colIndex = 4;
            gridControl1.CoveredRanges.Add(GridRangeInfo.Cells(rowIndex, 1, rowIndex, gridControl1.ColCount));
            gridControl1[rowIndex, 1]      = subheaderstyle;
            gridControl1[rowIndex, 1].Text = "TextBox Cells - represents the default textbox control in a cell as used for in - place editing";
            rowIndex++;
            gridControl1[rowIndex, colIndex].Text           = "TextBox";
            gridControl1[rowIndex, colIndex].CellType       = GridCellTypeName.TextBox;
            gridControl1[rowIndex, colIndex + 2].Text       = "TextBox/Image";
            gridControl1[rowIndex, colIndex + 2].CellType   = GridCellTypeName.TextBox;
            gridControl1[rowIndex, colIndex + 2].ImageIndex = 9;
            gridControl1.Model.ColWidths.ResizeToFit(GridRangeInfo.Col(colIndex + 2));
            #endregion

            #region MaskEditCells
            rowIndex += 2;
            gridControl1.CoveredRanges.Add(GridRangeInfo.Cells(rowIndex, 1, rowIndex + 1, gridControl1.ColCount));
            gridControl1[rowIndex, 1]      = headerstyle;
            gridControl1[rowIndex, 1].Text = "MaskEdit Cells";
            rowIndex++;
            rowIndex++;
            gridControl1.CoveredRanges.Add(GridRangeInfo.Cells(rowIndex, 1, rowIndex, gridControl1.ColCount));
            gridControl1[rowIndex, 1]      = subheaderstyle;
            gridControl1[rowIndex, 1].Text = "MaskEdit Cells - allow to mask any cell that permits valid inputs & also control the inputs values";

            rowIndex++;
            rowIndex++;
            gridControl1[rowIndex, colIndex].Text              = "Date Format";
            gridControl1[rowIndex, colIndex + 2].CellType      = GridCellTypeName.MaskEdit;
            gridControl1[rowIndex, colIndex + 2].MaskEdit.Mask = "99-99-99";
            gridControl1[rowIndex, colIndex + 2].FloatCell     = true;

            rowIndex++;
            rowIndex++;
            gridControl1[rowIndex, colIndex].Text = "First Name";
            GridStyleInfo    style1           = gridControl1[rowIndex, colIndex + 2];
            GridMaskEditInfo maskedEditStyle1 = style1.MaskEdit;

            rowIndex++;
            rowIndex++;
            gridControl1[rowIndex, colIndex].Text = "Last Name";
            GridStyleInfo    style2           = gridControl1[rowIndex, colIndex + 2];
            GridMaskEditInfo maskedEditStyle2 = style2.MaskEdit;

            rowIndex++;
            rowIndex++;
            gridControl1[rowIndex, colIndex].Text = "Telephone";
            GridStyleInfo    style3           = gridControl1[rowIndex, colIndex + 2];
            GridMaskEditInfo maskedEditStyle3 = style3.MaskEdit;

            rowIndex++;
            rowIndex++;
            gridControl1[rowIndex, colIndex].Text = "Social Security";
            GridStyleInfo    style4           = gridControl1[rowIndex, colIndex + 2];
            GridMaskEditInfo maskedEditStyle4 = style4.MaskEdit;

            #region MaskEditBoxes
            //
            // maskedEditBox1
            //
            style1.CellType = "MaskEdit";
            maskedEditStyle1.AllowPrompt   = false;
            maskedEditStyle1.ClipMode      = Syncfusion.Windows.Forms.Tools.ClipModes.ExcludeLiterals;
            style1.CultureInfo             = new System.Globalization.CultureInfo("en-US");
            maskedEditStyle1.DateSeparator = '-';
            maskedEditStyle1.Mask          = ">C<CCCCCCCCCCCC";
            style1.MaxLength = 13;
            style1.AutoSize  = true;
            maskedEditStyle1.SpecialCultureValue = Syncfusion.Windows.Forms.Tools.SpecialCultureValues.None;
            maskedEditStyle1.UseLocaleDefault    = false;
            maskedEditStyle1.UseUserOverride     = true;

            //
            // maskedEditBox2
            //
            style2.CellType = "MaskEdit";
            maskedEditStyle2.AllowPrompt   = false;
            maskedEditStyle2.ClipMode      = Syncfusion.Windows.Forms.Tools.ClipModes.IncludeLiterals;
            style2.CultureInfo             = new System.Globalization.CultureInfo("en-US");
            maskedEditStyle2.DateSeparator = '-';
            maskedEditStyle2.Mask          = "CCCCCCCCCCCCC";
            style2.MaxLength = 13;
            maskedEditStyle2.SpecialCultureValue = Syncfusion.Windows.Forms.Tools.SpecialCultureValues.None;
            style2.Text = "_____________";
            maskedEditStyle2.UseLocaleDefault = false;
            maskedEditStyle2.UseUserOverride  = true;
            //
            // maskedEditBox3
            //
            style3.CellType = "MaskEdit";
            maskedEditStyle3.AllowPrompt   = false;
            maskedEditStyle3.ClipMode      = Syncfusion.Windows.Forms.Tools.ClipModes.IncludeLiterals;
            style3.CultureInfo             = new System.Globalization.CultureInfo("en-US");
            maskedEditStyle3.DateSeparator = '-';
            maskedEditStyle3.Mask          = "(999) 999 - 9999";
            style3.MaxLength = 16;
            maskedEditStyle3.SpecialCultureValue = Syncfusion.Windows.Forms.Tools.SpecialCultureValues.None;
            style3.Text = "(___) ___ - ____";
            maskedEditStyle3.UseLocaleDefault = false;
            maskedEditStyle3.UseUserOverride  = true;
            //
            // maskedEditBox4
            //
            style4.CellType = "MaskEdit";
            maskedEditStyle4.AllowPrompt   = false;
            maskedEditStyle4.ClipMode      = Syncfusion.Windows.Forms.Tools.ClipModes.IncludeLiterals;
            style4.CultureInfo             = new System.Globalization.CultureInfo("en-US");
            maskedEditStyle4.DateSeparator = '-';
            maskedEditStyle4.Mask          = "999-99-9999";
            style4.MaxLength = 11;
            maskedEditStyle4.SpecialCultureValue = Syncfusion.Windows.Forms.Tools.SpecialCultureValues.None;
            style4.Text = "___-__-____";
            maskedEditStyle4.UseLocaleDefault = false;
            maskedEditStyle4.UseUserOverride  = true;
            #endregion
            #endregion

            #region NumericUpDown
            rowIndex++;
            rowIndex++;
            gridControl1.CoveredRanges.Add(GridRangeInfo.Cells(rowIndex, 1, rowIndex + 1, gridControl1.ColCount));
            gridControl1[rowIndex, 1]      = headerstyle;
            gridControl1[rowIndex, 1].Text = "NumericUpDown Cells";

            rowIndex += 3;
            // Wrapping, Range 0-20
            gridControl1[rowIndex, colIndex].Text                    = "With wrapping";
            gridControl1[rowIndex, colIndex + 2].CellType            = GridCellTypeName.NumericUpDown;
            gridControl1[rowIndex, colIndex + 2].Text                = "5";
            gridControl1[rowIndex, colIndex + 2].HorizontalAlignment = GridHorizontalAlignment.Right;
            gridControl1[rowIndex, colIndex + 2].NumericUpDown       = new GridNumericUpDownCellInfo(0, 20, 5, 1, true);

            rowIndex++;
            rowIndex++;
            gridControl1[rowIndex, colIndex].Text                    = "Without wrapping";
            gridControl1[rowIndex, colIndex + 2].CellType            = GridCellTypeName.NumericUpDown;
            gridControl1[rowIndex, colIndex + 2].Text                = "5";
            gridControl1[rowIndex, colIndex + 2].NumericUpDown       = new GridNumericUpDownCellInfo(1, 20, 1, 1, false);
            gridControl1[rowIndex, colIndex + 2].HorizontalAlignment = GridHorizontalAlignment.Right;
            #endregion

            #region Currency Cells
            rowIndex++;
            rowIndex++;
            gridControl1.CoveredRanges.Add(GridRangeInfo.Cells(rowIndex, 1, rowIndex + 1, gridControl1.ColCount));
            gridControl1[rowIndex, 1]      = headerstyle;
            gridControl1[rowIndex, 1].Text = "Currency Cells";

            rowIndex++;
            rowIndex++;
            gridControl1.CoveredRanges.Add(GridRangeInfo.Cells(rowIndex, 1, rowIndex, gridControl1.ColCount));
            gridControl1[rowIndex, 1]      = subheaderstyle;
            gridControl1[rowIndex, 1].Text = "Supports setting patterns to display (+), (-) numbers, grouping digits & decimal separators";

            #region CurrentStyle Settings
            GridStyleInfo currencyStyle = new GridStyleInfo();
            currencyStyle.CellType = GridCellTypeName.Currency;
            currencyStyle.CurrencyEdit.ClipMode = CurrencyClipModes.ExcludeFormatting;
            // Set formatting properties
            currencyStyle.CurrencyEdit.NullString               = "";
            currencyStyle.CurrencyEdit.CurrencyDecimalDigits    = 2;
            currencyStyle.CurrencyEdit.CurrencyDecimalSeparator = ".";
            currencyStyle.CurrencyEdit.CurrencyGroupSeparator   = ",";
            currencyStyle.CurrencyEdit.CurrencyGroupSizes       = new int[] { 3 };
            currencyStyle.CurrencyEdit.CurrencyNumberDigits     = 27;
            currencyStyle.CurrencyEdit.CurrencyPositivePattern  = 0;
            //currencyStyle.CurrencyEdit.CurrencySymbol = (row % 2 == 0) ? "$ " : "DM ";
            currencyStyle.TextColor = System.Drawing.Color.Black;
            currencyStyle.CurrencyEdit.NegativeColor = System.Drawing.Color.Red;
            currencyStyle.CurrencyEdit.NegativeSign  = "-";
            currencyStyle.CurrencyEdit.PositiveColor = System.Drawing.Color.Black;
            currencyStyle.FloatCell = true;
            #endregion

            rowIndex++;
            rowIndex++;
            gridControl1[rowIndex, colIndex - 2]           = currencyStyle;
            gridControl1[rowIndex, colIndex - 2].CellValue = 2;
            gridControl1[rowIndex, colIndex - 2].CurrencyEdit.CurrencyNegativePattern = 1;
            gridControl1[rowIndex, colIndex - 2].CurrencyEdit.CurrencySymbol          = "$ ";

            gridControl1[rowIndex, colIndex]           = currencyStyle;
            gridControl1[rowIndex, colIndex].CellValue = 4;
            gridControl1[rowIndex, colIndex].CurrencyEdit.CurrencyNegativePattern = 2;
            gridControl1[rowIndex, colIndex].CurrencyEdit.CurrencySymbol          = "DM";

            gridControl1[rowIndex, colIndex + 2]           = currencyStyle;
            gridControl1[rowIndex, colIndex + 2].CellValue = -6;
            gridControl1[rowIndex, colIndex + 2].CurrencyEdit.CurrencyNegativePattern = 1;
            gridControl1[rowIndex, colIndex + 2].CurrencyEdit.CurrencySymbol          = "$ ";

            gridControl1[rowIndex, colIndex + 4]           = currencyStyle;
            gridControl1[rowIndex, colIndex + 4].CellValue = -8;
            gridControl1[rowIndex, colIndex + 4].CurrencyEdit.CurrencyNegativePattern = 2;
            gridControl1[rowIndex, colIndex + 4].CurrencyEdit.CurrencySymbol          = "DM ";

            #endregion

            #region Password cells

            rowIndex++;
            rowIndex++;
            gridControl1.CoveredRanges.Add(GridRangeInfo.Cells(rowIndex, 1, rowIndex + 1, gridControl1.ColCount));
            gridControl1[rowIndex, 1]      = headerstyle;
            gridControl1[rowIndex, 1].Text = "Password Cells";

            rowIndex++;
            rowIndex++;
            gridControl1.CoveredRanges.Add(GridRangeInfo.Cells(rowIndex, 1, rowIndex, gridControl1.ColCount));
            gridControl1[rowIndex, 1]      = subheaderstyle;
            gridControl1[rowIndex, 1].Text = "Allows you to type a password, but only masking character like \" * \", will be displayed ";


            GridStyleInfo passwdStyle = new GridStyleInfo();
            for (int row = 37; row <= 45; row++)
            {
                passwdStyle = gridControl1[row, 2];
                passwdStyle.PasswordChar = '*';
                passwdStyle.CellType     = GridCellTypeName.OriginalTextBox;
                passwdStyle.Text         = new string((char)(65 + row), row);

                passwdStyle = gridControl1[row, 3];
                passwdStyle.CharacterCasing = CharacterCasing.Lower;
                passwdStyle.Text            = new string((char)(65 + row), row);

                passwdStyle = gridControl1[row, 4];
                passwdStyle.CharacterCasing = CharacterCasing.Upper;
                passwdStyle.Text            = new string((char)(65 + row), row);
            }
            #endregion

            gridControl1.CheckBoxClick += new GridCellClickEventHandler(gridControl1_CheckBoxClick);
            this.gridControl1.EndUpdate(true);
            #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;
     }
 }