Spread Sheet Merge Cells Selection Area Color

Posted by: addio777 on 1 February 2018, 7:58 am EST

    • Post Options:
    • Link

    Posted 1 February 2018, 7:58 am EST

    Hi !

    When I select Spead Sheet Merge Cell, I like to display it as attached image.

    I look for a solution.

    thank you.

  • Posted 6 February 2018, 7:13 am EST

    Thanks for the reply.

    There is one more question. MergePolicy.Restricted

    I want to select only merged cells.

    Thanks.

  • Posted 7 February 2018, 5:28 am EST

    Hello,

    Please refer the modified code as per your requirement.

    
    private void FpSpread1_SelectionChanged(object sender, FarPoint.Win.Spread.SelectionChangedEventArgs e)
            {
                int top_test=0, bottom_test=0;
                int top_Row = e.Range.Row-1, bottom_Row = e.Range.Row+1 ;
               
                    while (top_Row >= 0 && FpSpread1.ActiveSheet.Cells[top_Row, e.Range.Column].Value.ToString() == FpSpread1.ActiveSheet.Cells[e.Range.Row, e.Range.Column].Value.ToString()&& top_test == 0)
                    { 
                        for (int i = e.Range.Column; i >= 0; i--)
                        {
                            if (FpSpread1.ActiveSheet.Cells[top_Row, i].Value.ToString() != FpSpread1.ActiveSheet.Cells[e.Range.Row, i].Value.ToString())
                            {
                                top_test = 1;
                                break;
                            }
                            else
                            {
                                top_test = 0;
                            }
                        }
                        if (top_test == 0)
                            top_Row = top_Row - 1;
                    }
               
                    while (bottom_Row < FpSpread1.ActiveSheet.RowCount && FpSpread1.ActiveSheet.Cells[bottom_Row, e.Range.Column].Value.ToString() == FpSpread1.ActiveSheet.Cells[e.Range.Row, e.Range.Column].Value.ToString() && bottom_test == 0)
                    {
                        for (int i = e.Range.Column; i >= 0; i--)
                        {
                            if (FpSpread1.ActiveSheet.Cells[bottom_Row, i].Value.ToString() != FpSpread1.ActiveSheet.Cells[e.Range.Row, i].Value.ToString())
                            {
                                bottom_test = 1;
                                break;
                            }
                            else
                            {
                                bottom_test = 0;
                            }
                        }
                       if (bottom_test == 0)
                            bottom_Row = bottom_Row + 1;
                    }
                FpSpread1.ActiveSheet.AddSelection(top_Row+1, e.Range.Column, bottom_Row - top_Row-1, 1);
            }
    
    

    Also, refer the attached sample.

    Thanks,

    Mohit

    Prj_CellSpan_modfied.zip

  • Posted 7 February 2018, 5:30 am EST

    Hello,

    I am assuming that you are using automatic merging feature of spread. It is designed behaviour of spread that Merged cells do not lose their data; it is simply hidden by the merge. You can edit a cell that is merged with another cell. However, you can manually change the selection in “SelectionChanged” event. Please refer the following code:

    
    private void FpSpread1_SelectionChanged(object sender, FarPoint.Win.Spread.SelectionChangedEventArgs e)
           {
               int top_Row = e.Range.Row-1, bottom_Row = e.Range.Row+1 ;
               while(top_Row >= 0&&FpSpread1.ActiveSheet.Cells[top_Row,e.Range.Column].Value.ToString() == FpSpread1.ActiveSheet.Cells[e.Range.Row,e.Range.Column].Value.ToString())
               {
                   top_Row = top_Row - 1;
               }
               while (bottom_Row < FpSpread1.ActiveSheet.RowCount && FpSpread1.ActiveSheet.Cells[bottom_Row, e.Range.Column].Value.ToString() == FpSpread1.ActiveSheet.Cells[e.Range.Row, e.Range.Column].Value.ToString() )
               {
                   bottom_Row = bottom_Row + 1;
               }
    
               FpSpread1.ActiveSheet.AddSelection(top_Row+1, e.Range.Column, bottom_Row - top_Row-1, 1);
           }
    
    

    Also, refer the attached sample for implmenting the same.

    If our assumption is incorrect. Kindly explain your requirement in more details

    Thanks,

    Mohit

    Prj_CellSpan.zip

Need extra support?

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

Learn More

Forum Channels