Beispiel #1
0
        //control the current cell
        void gridGroupingControl1_TableControlCurrentCellActivated(object sender, GridTableControlEventArgs e)
        {
            // Retrieve the current element
            Element el = GetNestedCurrentElement();

            if (el != null)
            {
                Record r = el.GetRecord();
                // current field.
                if (r != null)
                {
                    GridTable table = (GridTable)r.ParentDetails.ParentChildTable.ParentTable;

                    FieldDescriptor fd = table.CurrentRecordManager.CurrentField;
                    if (fd != null)
                    {
                        this.lblCell.Text = r.GetValue(fd.Name).ToString();

                        // TableCellStyle
                        GridTableCellStyleInfo style = table.GetTableCellStyle(r, fd);
                        this.lblCell.Text += " (" + style.ToString().Replace('\n', ';') + ")";

                        GridTableCellStyleInfoIdentity identity = style.TableCellIdentity;

                        // you can check identity for more information about cell.
                    }
                }
                // Record
                this.lblElement.Text = el.ToString();
            }
        }
Beispiel #2
0
        /// <summary>
        /// Helper routine for drawing picture in covered range of column Employees_Photo.
        /// </summary>
        void TableModel_QueryCoveredRange(object sender, GridQueryCoveredRangeEventArgs e)
        {
            GridTableModel model = (GridTableModel)sender;
            GridTable      table = model.Table;

            if (e.RowIndex < table.DisplayElements.Count)
            {
                // Get the element displayed at the row
                Element el = table.DisplayElements[e.RowIndex];

                // Check if element is a record (could also be a column header or group caption ...)
                if (Element.IsRecord(el) && el.ParentGroup != null)
                {
                    GridTableCellStyleInfo         style = model[e.RowIndex, e.ColIndex];
                    GridTableCellStyleInfoIdentity id    = style.TableCellIdentity;
                    // The cell identity contains column information. We check if the column is Employees_Photo
                    if (id.Column != null && id.Column.MappingName == Employees_Photo)
                    {
                        Group group = el.ParentGroup;

                        // Grouped by Customers_ContactName - Do not cover cells if not grouped by Employee ...
                        if (group != null && group.CategoryColumns.Count > 0 && group.CategoryColumns[0].Name == Customers_ContactName)
                        {
                            int tablePos = table.DisplayElements.IndexOf(group);
                            int firstRow = tablePos + 1;
                            int lastRow  = tablePos + group.GetVisibleCount() - 1;
                            e.Range = GridRangeInfo.Cells(firstRow, e.ColIndex, lastRow, e.ColIndex);
                            gridGroupingControl1.TableModel.CoveredRanges.Add(e.Range);
                            e.Handled = true;
                        }
                    }
                }
            }
        }
Beispiel #3
0
        private void gridGroupingControl1_TableControlCellDrawn(object sender, GridTableControlDrawCellEventArgs e)
        {
            GridTableCellStyleInfo         style = e.TableControl.Model[e.Inner.RowIndex, e.Inner.ColIndex];
            GridTableCellStyleInfoIdentity id    = style.TableCellIdentity;

            Element el = id.DisplayElement;

            if (el is ExtraSection)
            {
                if (id.ColIndex == 0)
                {
                    // Row Header and ExtraSection is CurrentElement
                    if (el == el.ParentTable.CurrentElement)
                    {
                        // Draw Record indicator
                        try
                        {
                            Rectangle iconBounds = Rectangle.FromLTRB(e.Inner.Bounds.Right - 15, e.Inner.Bounds.Top, e.Inner.Bounds.Right, e.Inner.Bounds.Bottom);
                            iconBounds.Offset(-2, 0);
                            IconPainter.PaintIcon(e.Inner.Graphics, iconBounds, Point.Empty, "SFARROW.BMP", style.TextColor);
                        }
                        catch
                        { }
                    }
                }
            }
        }
Beispiel #4
0
        private void gridGroupingControl1_TableControlCurrentCellActivated(object sender, GridTableControlEventArgs e)
        {
            // Navigate to ExtraSection when textbox inside ExtraSection has become CurrentCell.

            GridCurrentCell                gcc   = e.TableControl.CurrentCell;
            GridTableCellStyleInfo         style = e.TableControl.Model[gcc.RowIndex, gcc.ColIndex];
            GridTableCellStyleInfoIdentity id    = style.TableCellIdentity;

            if (id.DisplayElement is ExtraSection)
            {
                id.Table.CurrentRecordManager.NavigateTo(id.DisplayElement);
            }
        }
Beispiel #5
0
        void TableControl_PrepareViewStyleInfo(object sender, Syncfusion.Windows.Forms.Grid.GridPrepareViewStyleInfoEventArgs e)
        {
            GridTableCellStyleInfo         style = (GridTableCellStyleInfo)e.Style;
            GridTableCellStyleInfoIdentity id    = style.TableCellIdentity;

            // Cell identity contains information about the cell (element, column etc.)

            // Check if this is a indent cell
            if (id.TableCellType == GridTableCellType.GroupIndentCell)
            {
                Group group = id.DisplayElement.ParentGroup;

                // Check if this is the indent of a Categories_CategoryName group.
                if (group != null && group.CategoryColumns.Count > 0 && group.CategoryColumns[0].Name == Customers_ContactName)
                {
                    // And if the group is not empty ...
                    if (group.Records.Count > 0)
                    {
                        // Get the category name from the first record
                        Record r     = group.Records[0];
                        object value = r.GetValue(Customers_ContactName);

                        // Should be a string
                        string empName = value as string;

                        // Assign the name to the CellValue of the Indent cell and also adjust the font, color and other style settings.
                        if (empName != null)
                        {
                            style.Interior            = new BrushInfo(GradientStyle.Vertical, Color.FromArgb(219, 226, 242), Color.FromArgb(255, 187, 111));
                            style.CellValue           = empName;
                            style.CellType            = "Static";
                            style.HorizontalAlignment = GridHorizontalAlignment.Center;
                            style.VerticalAlignment   = GridVerticalAlignment.Middle;
                            style.Trimming            = StringTrimming.EllipsisCharacter;
                            style.Font.Bold           = true;
                            style.Font.Italic         = true;
                            style.Font.Orientation    = 270;
                        }
                    }
                }
            }
            if (e.Style.CellType.ToString() == "Image")
            {
                e.Style.ImageSizeMode = GridImageSizeMode.CenterImage;
            }
        }
Beispiel #6
0
        private void gridGroupingControl1_TableControlCellMouseHover(object sender, GridTableControlCellMouseEventArgs e)
        {
            GridTableCellStyleInfo         style = (GridTableCellStyleInfo)e.TableControl.Model[e.Inner.RowIndex, e.Inner.ColIndex];
            GridTableCellStyleInfoIdentity id    = style.TableCellIdentity;

            //
            // Note the check for not being a GridTableCellType.NestedTableCell below. If the mouse hovers
            // over an area of a nested table, this event will get hit twice: First for the outer
            // TableControl (which routes the event to the inner TableControl) and then afterward
            // for the inner TableControl. For the outer TableControl the TableCellType
            // is GridTableCellType.NestedTableCell
            //
            if (id.TableCellType != GridTableCellType.NestedTableCell)
            {
                string column = (id.Column != null) ? id.Column.ToString() : "";
                Console.WriteLine("MouseHover over " + id.TableCellType.ToString() + "(" + column + ", " + id.DisplayElement.GetType().Name + ")");
            }
        }
Beispiel #7
0
        private void gridGroupingControl1_TableControlCellClick(object sender, GridTableControlCellClickEventArgs e)
        {
            GridTableCellStyleInfo         style = (GridTableCellStyleInfo)e.TableControl.Model[e.Inner.RowIndex, e.Inner.ColIndex];
            GridTableCellStyleInfoIdentity id    = style.TableCellIdentity;

            if (id.TableCellType == GridTableCellType.ColumnHeaderCell
                )
            {
                // Workaround - gridGroupingControl1_TableControlCellButtonClicked does not get hit so
                // we'll check for the area where the button is and set e.Inner.Cancel = true
                GridCellRendererBase r = e.TableControl.CellRenderers[style.CellType];
                r.PerformLayout(e.Inner.RowIndex, e.Inner.ColIndex, style, e.TableControl.RangeInfoToRectangle(GridRangeInfo.Cell(e.Inner.RowIndex, e.Inner.ColIndex)));
                if (r.RaiseHitTest(e.Inner.RowIndex, e.Inner.ColIndex, e.Inner.MouseEventArgs, null) == GridHitTestContext.CellButtonElement)
                {
                    string column = (id.Column != null) ? id.Column.ToString() : "";
                    string s      = "Clicked on " + id.TableCellType.ToString() + "(" + column + ", " + id.DisplayElement.GetType().Name + ")";

                    MessageBox.Show(s);
                    e.Inner.Cancel = true;
                }
            }
        }
Beispiel #8
0
        private void gridGroupingControl1_TableControlCellButtonClicked(object sender, GridTableControlCellButtonClickedEventArgs e)
        {
            GridTableCellStyleInfo         style = (GridTableCellStyleInfo)e.TableControl.Model[e.Inner.RowIndex, e.Inner.ColIndex];
            GridTableCellStyleInfoIdentity id    = style.TableCellIdentity;

            if (id.TableCellType != GridTableCellType.NestedTableCell)
            {
                string column = (id.Column != null) ? id.Column.ToString() : "";
                string s      = "TableControlCellButtonClicked on " + id.TableCellType.ToString() + "(" + column + ", " + id.DisplayElement.GetType().Name + ")";

                Console.WriteLine(s);
                e.Inner.Cancel = true;
            }

            if (id.TableCellType == GridTableCellType.RecordPlusMinusCell)
            {
                // Expand record without moving current record to that record (change default behavior
                // of grid).
                Record r = id.DisplayElement.ParentRecord;
                r.IsExpanded   = !r.IsExpanded;
                e.Inner.Cancel = true;  // don't let grid handle CellButtonClicked - otherwise it would reverse the IsExpanded call.
            }
        }
Beispiel #9
0
        /// <summary>
        /// Helper routine for drawing picture in covered range of column Employees_Photo.
        /// </summary>
        void gridGroupingControl1_TableControlCellDrawn(object sender, GridTableControlDrawCellEventArgs e)
        {
            GridTableCellStyleInfo         style = (GridTableCellStyleInfo)e.Inner.Style;
            GridTableCellStyleInfoIdentity id    = style.TableCellIdentity;

            // Employees_Photo column
            if (id.Column != null && id.Column.MappingName == Employees_Photo)
            {
                Group group = id.DisplayElement.ParentGroup;

                // Grouped by Customers_ContactName
                if (group != null && group.CategoryColumns.Count > 0 && group.CategoryColumns[0].Name == Customers_ContactName)
                {
                    if (group.Records.Count > 0)
                    {
                        Record r = group.Records[0];

                        object value = r.GetValue(id.Column.FieldDescriptor);

                        // Should be byte[] (image stream ...)
                        byte[] byteStream = value as byte[];

                        if (byteStream != null)
                        {
                            Graphics  graphics = e.Inner.Graphics;
                            Image     image    = GridImageUtil.ConvertToImage(byteStream);
                            Rectangle bounds   = e.Inner.Bounds;
                            bounds = GridMargins.RemoveMargins(bounds, style.TextMargins.ToMargins());
                            bounds = GridMargins.RemoveMargins(bounds, style.BorderMargins.ToMargins());
                            style.ImageSizeMode = GridImageSizeMode.CenterImage;
                            GridImageUtil.DrawImage(image, bounds, graphics, bounds, style, false);
                            e.Inner.Cancel = true; // signals you did your own drawing.
                        }
                    }
                }
            }
        }
Beispiel #10
0
        /// <summary>
        /// A method that returns filter collection applied so far to the respective column.
        /// </summary>
        /// <param name="recordFilters">Filtercollection</param>
        /// <param name="tableCellIdentity">StyleInfoIdentity</param>
        /// <returns>Collection of filters.</returns>
        private IEnumerable <RecordFilterDescriptor> GetFilters(RecordFilterDescriptorCollection recordFilters, GridTableCellStyleInfoIdentity tableCellIdentity)
        {
            var rfdc = recordFilters.GetRecordFilters(tableCellIdentity.Column.MappingName);

            if (rfdc != null)
            {
                var uniqueId = tableCellIdentity.DisplayElement.ParentGroup.UniqueGroupId;
                var rfdList  = new ArrayList();
                foreach (var rfd in rfdc)
                {
                    if (rfd.CompareUniqueId(uniqueId))
                    {
                        rfdList.Add(rfd);
                    }
                }

                if (rfdList.Count > 0)
                {
                    return((RecordFilterDescriptor[])rfdList.ToArray(typeof(RecordFilterDescriptor)));
                }
            }
            return(null);
        }
Beispiel #11
0
 /// <summary>
 /// An overridden method that gets called when the filter dropdown is opened.
 /// </summary>
 /// <param name="tableCellIdentity">StyleInfoIdentity</param>
 /// <returns>Set of filter items.</returns>
 public override object[] GetFilterBarChoices(GridTableCellStyleInfoIdentity tableCellIdentity)
 {
     _identity = tableCellIdentity;
     return(GetFilterValues(_identity.Column));
 }