C1.WPF.FlexGrid.CellFactory -> Code Breaking inside Overriden CreateCell()

Posted by: abdul.muqsit on 8 December 2021, 6:01 am EST

    • Post Options:
    • Link

    Posted 8 December 2021, 6:01 am EST

    Code Breaking Inside Overriden Create Cell

    public override FrameworkElement CreateCell(C1.WPF.FlexGrid.C1FlexGrid grid, C1.WPF.FlexGrid.CellType cellType, C1.WPF.FlexGrid.CellRange range)

    {

    FrameworkElement createCell = base.CreateCell(grid, cellType, range);

    if ((grid[range.Row, range.Column] is ARReadOnlyValueBridge) || (grid[range.Row, range.Column] is ARConstantMOComboBoxBridge))

    {

    BehaviorCollection behaviors = Interaction.GetBehaviors(createCell);

    behaviors.Add(new DragBehavior((FinancialsGrid)grid));

    }

    //if(range.Row > -1 && range.Column > -1)

    //{

            //}
    
            return createCell;
        }
    

    We were using C1.WPF.FlexGrid.4 and it is working fine with that Dll. but for Analysis when I updated to C1.WPF.FlexGrid.4.5.2(latest version). the code (grid[range.Row, range.Column) is breaking saying index out of range.

    Can you please help ? what has changed in the latest version ? any help would be appriciated.

    Regards,

    Abdul Muqsit.

    Thanks

  • Posted 8 December 2021, 7:37 am EST

    Hi,

    Thanks for the code snippet.

    JFYI, CreateCell calls for every CellType i.e., BottomRight, TopLeft, ColumnHeaders, RowHeaders and Cells.

    It seems like you are working with cells, so we suggests you to validate your code for CellType.Cell. Then the CellRange will keeps in range accordingly.

    It may be possible that it breaks on CellType.BottomRight where CellRange keeps out of range. (see code snippet)

    
     public override FrameworkElement CreateCell(C1FlexGrid grid, CellType cellType, CellRange range)
            {
                FrameworkElement createCell = base.CreateCell(grid, cellType, range);
                if(cellType == CellType.Cell)
                {
                    if (grid[range.Row, range.Column] == null)
                    {
                        //Do Your code
                    }
                }            
                return createCell;
            }
    
    

    Please refer the attached sample for the same : FlexgridCellFactoryDemo.zip

    Best Regards,

    Nitin

Need extra support?

Upgrade your support plan and get personal unlimited phone support with our customer engagement team

Learn More

Forum Channels