Forcing Cell Formating outside of CellFormatting

3 posts, 0 answers
  1. Bruno
    Bruno avatar
    7 posts
    Member since:
    Sep 2017

    Posted 12 Dec 2017 Link to this post

    Is it possible to force a cell formatting outside the event for it? EveryWhere i look it's refering us back to CellFormating Event.

    I've try multiple option Using the CellFormatting Event that have generating undesired result because of Virtualisation UI.

    I've manage to make it refresh on scrolling but the UI slowed down to the point it's not viable anymore.

    Basically i am using DragAndDrop from 1 grid to another and then i'm trying to validate if the selected COLUMN match certain criteria.

    this is the final step in my project and would gladly need help to find a solution.

     

    private void svc_PreviewDragDrop(object sender, RadDropEventArgs e)
            {
                SnapshotDragItem draggedItem = e.DragInstance as SnapshotDragItem;
                GridHeaderCellElement targetHeaderCell = e.HitTarget as GridHeaderCellElement;
                if (draggedItem == null || targetHeaderCell == null)
                {
                    return;
                }
                GridHeaderCellElement sourceHeaderCell = draggedItem.Item as GridHeaderCellElement;
                 
                if (sourceHeaderCell != null)
                {
                    e.Handled = true;
                    for (int i = 0; i < gridSource.RowCount; i++)
                    {
                        gridTarget.Rows[i].Cells[targetHeaderCell.ColumnIndex].Value = gridSource.Rows[i].Cells[sourceHeaderCell.ColumnIndex].Value;                   
                    }
                    if(Mycondition(gridTarget,Rows[i].Cells[targetHeaderCell.ColumnIndex].Value.toString(), dataType))
                    {
                       gridTarget,Rows[i].Cells[targetHeaderCell.ColumnIndex].style.backcolor = Color.Red
                       gridTarget,Rows[i].Cells[targetHeaderCell.ColumnIndex].style.Drawfill = true;
                    }
                }           
            }
  2. Bruno
    Bruno avatar
    7 posts
    Member since:
    Sep 2017

    Posted 12 Dec 2017 Link to this post

    I've Found a solution in a previous post ... Page 18.... this might need a small cleanup/Regrouping :)

    private void svc_PreviewDragDrop(object sender, RadDropEventArgs e)
            {
                SnapshotDragItem draggedItem = e.DragInstance as SnapshotDragItem;
                GridHeaderCellElement targetHeaderCell = e.HitTarget as GridHeaderCellElement;
                if (draggedItem == null || targetHeaderCell == null)
                {
                    return;
                }
                GridHeaderCellElement sourceHeaderCell = draggedItem.Item as GridHeaderCellElement;
                 
                if (sourceHeaderCell != null)
                {
                    e.Handled = true;
                    for (int i = 0; i < gridSource.RowCount; i++)
                    {
                        gridTarget.Rows[i].Cells[targetHeaderCell.ColumnIndex].Value = gridSource.Rows[i].Cells[sourceHeaderCell.ColumnIndex].Value;
                        if (gridTarget.Rows[i].Cells[targetHeaderCell.ColumnIndex].Value != null)
                        {
                            StyleCell(gridTarget.Rows[i].Cells[targetHeaderCell.ColumnIndex],
                                !validator.Typevalidator(gridTarget.Rows[i].Cells[targetHeaderCell.ColumnIndex].Value.ToString(),
                                                        ds[targetHeaderCell.ColumnIndex].PropertyType));
                        }
                    }
                }           
            }
            #endregion
            private void StyleCell(GridViewCellInfo cell, bool status)
            {
                if (status)
                {
                    cell.Style.CustomizeFill = true;
                    cell.Style.GradientStyle = GradientStyles.Solid;
                    cell.Style.BackColor = Color.Red;
                }
                else
                {
                    cell.Style.CustomizeFill = true;
                    cell.Style.GradientStyle = GradientStyles.Solid;
                    cell.Style.BackColor = Color.White;
     
                }
            }
     
            private void gridTarget_CellEndEdit(object sender, GridViewCellEventArgs e)
            {
                if (gridTarget.Rows[e.RowIndex].Cells[e.ColumnIndex].Value != null)
                {
                    StyleCell(gridTarget.Rows[e.RowIndex].Cells[e.ColumnIndex],
                                !validator.Typevalidator(gridTarget.Rows[e.RowIndex].Cells[e.ColumnIndex].Value.ToString(),
                                                        ds[e.ColumnIndex].PropertyType));
                }
            }
        }

     

  3. Dess | Tech Support Engineer, Sr.
    Admin
    Dess | Tech Support Engineer, Sr.  avatar
    3201 posts

    Posted 13 Dec 2017 Link to this post

    Hello, Bruno,

    Thank you for writing.  

    In order to force the CellFormatting event to be fired to be fired it is necessary to Refresh the MasterTemplate. As to the formatting note that due to the UI virtualization in RadGridView, cell elements are created only for currently visible cells and are being reused during operations like scrolling, filtering, grouping and so on. In order to prevent applying the formatting to other columns' cell elements (because of the cell reuse), all customization should be reset for the rest of the cell elements. The following help article is quite useful on this topic: https://docs.telerik.com/devtools/winforms/gridview/cells/formatting-cells

    I hope this information helps. Should you have further questions I would be glad to help.
     
    Regards,
    Dess
    Progress Telerik
    Try our brand new, jQuery-free Angular components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
Back to Top