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

    <FONT face="Times New Roman" size=3>Below is the code that can be used to CheckAll & ClearAll Rows for the entire column. On clicking the CheckBox in the Header, c</FONT><FONT face="Times New Roman" size=3>olumn gets selected for a second, selecting the entire rows in that particular column and then disappears as a result of ClearSelections being called.</FONT>


    <o:p><FONT face="Times New Roman" size=3> </FONT></o:p>


    <FONT face="Times New Roman" size=3>public static bool isEnabled = false;</FONT>


    <o:p><FONT face="Times New Roman" size=3> </FONT></o:p>


    <FONT size=3><FONT face="Times New Roman">private void Form1_Load(object sender, EventArgs e)<o:p></o:p></FONT></FONT>


    <FONT size=3><FONT face="Times New Roman"><SPAN style="mso-spacerun:yes;">        </SPAN>{<o:p></o:p></FONT></FONT>


    <FONT size=3><FONT face="Times New Roman"><SPAN style="mso-spacerun:yes;">            </SPAN>FarPoint.Win.Spread.CellType.CheckBoxCellType chkBox = new FarPoint.Win.Spread.CellType.CheckBoxCellType();</FONT></FONT>


    <FONT size=3><FONT face="Times New Roman"><SPAN style="mso-spacerun:yes;">            </SPAN>fpSpread1.ActiveSheet.ColumnHeader.Columns[1].CellType = chkBox;<o:p></o:p></FONT></FONT>


    <FONT size=3><FONT face="Times New Roman"><SPAN style="mso-spacerun:yes;">            </SPAN>fpSpread1.ActiveSheet.Columns[1].CellType = chkBox;<o:p></o:p></FONT></FONT>


    <FONT face="Times New Roman" size=3>}</FONT>


    <o:p><FONT face="Times New Roman" size=3> </FONT></o:p>


    <o:p><FONT face="Times New Roman" size=3> </FONT></o:p>


    <FONT size=3><FONT face="Times New Roman">private void fpSpread1_CellClick(object sender, FarPoint.Win.Spread.CellClickEventArgs e)<o:p></o:p></FONT></FONT>


    <FONT size=3><FONT face="Times New Roman"><SPAN style="mso-spacerun:yes;">        </SPAN>{</FONT></FONT>


    <FONT face="Times New Roman" color=#006600 size=3>//***** We may use the code below to check all the checkboxes under this column ****</FONT>


    <o:p><FONT face="Times New Roman" size=3> </FONT></o:p>


    <FONT size=3><FONT face="Times New Roman"><SPAN style="mso-spacerun:yes;">            </SPAN>if (e.ColumnHeader == true && e.Column == 1 && isEnabled == false)<o:p></o:p></FONT></FONT>


    <FONT size=3><FONT face="Times New Roman"><SPAN style="mso-spacerun:yes;">            </SPAN>{<o:p></o:p></FONT></FONT>


    <FONT size=3><FONT face="Times New Roman"><SPAN style="mso-spacerun:yes;">                </SPAN>isEnabled = true;<o:p></o:p></FONT></FONT>


    <FONT size=3><FONT face="Times New Roman"><SPAN style="mso-spacerun:yes;">                </SPAN>fpSpread1.ActiveSheet.ColumnHeader.Cells[0, 1].Value = true;<o:p></o:p></FONT></FONT>


    <FONT size=3><FONT face="Times New Roman"><SPAN style="mso-spacerun:yes;">                </SPAN>for (int rowCount = 0; rowCount < fpSpread1.ActiveSheet.Rows.Count; rowCount++)<o:p></o:p></FONT></FONT>


    <FONT size=3><FONT face="Times New Roman"><SPAN style="mso-spacerun:yes;">                </SPAN>{<o:p></o:p></FONT></FONT>


    <FONT size=3><FONT face="Times New Roman"><SPAN style="mso-spacerun:yes;">                    </SPAN>fpSpread1.ActiveSheet.Cells[rowCount, 1].Value = true;<o:p></o:p></FONT></FONT>


    <FONT size=3><FONT face="Times New Roman"><SPAN style="mso-spacerun:yes;">                </SPAN>}</FONT></FONT>


    <FONT size=3><FONT face="Times New Roman"><SPAN style="mso-spacerun:yes;">      </SPAN><SPAN style="mso-spacerun:yes;"> </SPAN>}</FONT></FONT>


    <FONT face="Times New Roman" color=#006600 size=3>//***** We may use the code below to uncheck all the checkboxes *******</FONT>


    <o:p><FONT face="Times New Roman" size=3> </FONT></o:p><FONT size=3><FONT face="Times New Roman"><SPAN style="mso-spacerun:yes;">            </SPAN>else<o:p></o:p></FONT></FONT>


    <FONT size=3><FONT face="Times New Roman"><SPAN style="mso-spacerun:yes;">                </SPAN>if (e.ColumnHeader == true && e.Column == 1 && isEnabled == true)<o:p></o:p></FONT></FONT>


    <FONT size=3><FONT face="Times New Roman"><SPAN style="mso-spacerun:yes;">                </SPAN>{<o:p></o:p></FONT></FONT>


    <FONT size=3><FONT face="Times New Roman"><SPAN style="mso-spacerun:yes;">                    </SPAN>isEnabled = false;<o:p></o:p></FONT></FONT>


    <FONT size=3><FONT face="Times New Roman"><SPAN style="mso-spacerun:yes;">                    </SPAN>fpSpread1.ActiveSheet.ColumnHeader.Cells[0, 1].Value = false;<o:p></o:p></FONT></FONT>


    <FONT size=3><FONT face="Times New Roman"><SPAN style="mso-spacerun:yes;">                </SPAN><SPAN style="mso-spacerun:yes;">    </SPAN>for (int rowCount = 0; rowCount < fpSpread1.ActiveSheet.Rows.Count; rowCount++)<o:p></o:p></FONT></FONT>


    <FONT size=3><FONT face="Times New Roman"><SPAN style="mso-spacerun:yes;">                    </SPAN>{<o:p></o:p></FONT></FONT>


    <FONT size=3><FONT face="Times New Roman"><SPAN style="mso-spacerun:yes;">                        </SPAN>fpSpread1.ActiveSheet.Cells[rowCount, 1].Value = false;<o:p></o:p></FONT></FONT>


    <FONT size=3><FONT face="Times New Roman"><SPAN style="mso-spacerun:yes;">                    </SPAN>}<o:p></o:p></FONT></FONT>


    <FONT size=3><FONT face="Times New Roman"><SPAN style="mso-spacerun:yes;">                </SPAN>}<o:p></o:p></FONT></FONT>


    <FONT size=3><FONT face="Times New Roman"><SPAN style="mso-spacerun:yes;">        </SPAN>}</FONT></FONT>


    <FONT size=3><FONT face="Times New Roman">private void fpSpread1_SelectionChanged(object sender, FarPoint.Win.Spread.SelectionChangedEventArgs e)<o:p></o:p></FONT></FONT>


    <FONT size=3><FONT face="Times New Roman"><SPAN style="mso-spacerun:yes;">        </SPAN>{<o:p></o:p></FONT></FONT>


    <FONT size=3><FONT face="Times New Roman"><SPAN style="mso-spacerun:yes;">            </SPAN><SPAN style="mso-spacerun:yes;">  </SPAN>fpSpread1.ActiveSheet.ClearSelection();   </FONT></FONT>


    <FONT size=3><FONT face="Times New Roman"><SPAN style="mso-spacerun:yes;"> </SPAN><SPAN style="mso-spacerun:yes;">        </SPAN>}</FONT></FONT>


    <FONT face="Times New Roman" size=3></FONT> 


    <FONT face="Times New Roman" size=3></FONT> 


    <FONT face="Times New Roman" size=3>Thanks</FONT>


    <FONT face="Times New Roman" size=3>Reeva</FONT>

  • 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