ClearSelections in code not working when user clicks in ColumnHeader

Posted by: j2associates on 8 September 2017, 2:05 pm EST

  • Posted 8 September 2017, 2:05 pm EST

    Hello all,


    We are trapping the CellClick event to do some processing when the user clicks certain cells in the ColumnHeader. At the end of the processing, the code calls ClearSelections but the column selection is not cleared until you click away in the data area somewhere. Thanks in advance for any ideas and/or suggestions!

  • Replied 8 September 2017, 2:05 pm EST

    The column selection is not cleared in this case because the CellClick event fires before the column gets selected. Since the column has not been selected yet so there is nothing to clear when ClearSelections is being called.


    You can actually trap SelChange event and call ClearSelection in it to see that column gets selected for a second and then disappears as a result of ClearSelections being called.


    Can you please share what you are actually trying to do by calling ClearSelections in CellClick event?


    Thanks.

  • Replied 8 September 2017, 2:05 pm EST

    Thanks for the explanation, that makes sense. We have a CheckBox in the header that acts as a CheckAll, ClearAll for the entire column. We trap the CellClick event and manually toggle the ColumnHeader.Cells value back and forth. Attached is a jpeg file to give you an idea.
    2009/10/CheckBoxHeaders.JPG
  • Replied 8 September 2017, 2:05 pm EST

    Below is the code that can be used to CheckAll & ClearAll Rows for the entire column. On clicking the CheckBox in the Header, column gets selected for a second, selecting the entire rows in that particular column and then disappears as a result of ClearSelections being called.


     


    public static bool isEnabled = false;


     


    private void Form1_Load(object sender, EventArgs e)


            {


                FarPoint.Win.Spread.CellType.CheckBoxCellType chkBox = new FarPoint.Win.Spread.CellType.CheckBoxCellType();


                fpSpread1.ActiveSheet.ColumnHeader.Columns[1].CellType = chkBox;


                fpSpread1.ActiveSheet.Columns[1].CellType = chkBox;


    }


     


     


    private void fpSpread1_CellClick(object sender, FarPoint.Win.Spread.CellClickEventArgs e)


            {


    //***** We may use the code below to check all the checkboxes under this column ****


     


                if (e.ColumnHeader == true && e.Column == 1 && isEnabled == false)


                {


                    isEnabled = true;


                    fpSpread1.ActiveSheet.ColumnHeader.Cells[0, 1].Value = true;


                    for (int rowCount = 0; rowCount < fpSpread1.ActiveSheet.Rows.Count; rowCount++)


                    {


                        fpSpread1.ActiveSheet.Cells[rowCount, 1].Value = true;


                    }


           }


    //***** We may use the code below to uncheck all the checkboxes *******


                 else


                    if (e.ColumnHeader == true && e.Column == 1 && isEnabled == true)


                    {


                        isEnabled = false;


                        fpSpread1.ActiveSheet.ColumnHeader.Cells[0, 1].Value = false;


                        for (int rowCount = 0; rowCount < fpSpread1.ActiveSheet.Rows.Count; rowCount++)


                        {


                            fpSpread1.ActiveSheet.Cells[rowCount, 1].Value = false;


                        }


                    }


            }


    private void fpSpread1_SelectionChanged(object sender, FarPoint.Win.Spread.SelectionChangedEventArgs e)


            {


                  fpSpread1.ActiveSheet.ClearSelection();   


             }


     


     


    Thanks


    Reeva

  • Replied 8 September 2017, 2:05 pm EST

    Hello Reeva,


    A belated thanks for your response. That is the code that I needed. Oddly enough, the SelectionChanging event never fires as I tried to cancel it but was unable to do so.

Need extra support?

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

Learn More

Forum Channels