Checkboxcelltype and buttonclick within column but not on checkbox

Posted by: loy-chan on 8 September 2017, 4:35 am EST

  • Posted 8 September 2017, 4:35 am EST

    I have an odd situation that my client wants to see if I can do something about ...


    I have a checkbox column that is pretty wide due to the header text. I have a button click event on the checkbox which works fine if the user intends to change the checkbox value.


    A problem occurs when my user is on another window and wants to return focus to my FP application. If my user accidentily checks a checkbox column (but outside of the actual checkbox) it will still fire the button click event.


    Is there anyway that I can easily prevent the click event from firing?


    Thanks


     


    Loy.

  • Replied 8 September 2017, 4:35 am EST

    You can create a custom celltype and override the IsReservedLocation...

    Public Class MyCheck
    Inherits FarPoint.Win.Spread.CellType.CheckBoxCellType

    Public Overrides Function IsReservedLocation(ByVal g As System.Drawing.Graphics, ByVal x As Integer, ByVal y As Integer, ByVal rc As System.Drawing.Rectangle, ByVal appearance As FarPoint.Win.Spread.Appearance, ByVal value As Object, ByVal zoomFactor As Single) As Object
    Dim rectCheck As New Rectangle(rc.Left + 2, rc.Top + 2, 14, 14)
    If rectCheck.Contains(x, y) Then

    Return MyBase.IsReservedLocation(g, x, y, rc, appearance, value, zoomFactor)

    Else

    Return Nothing

    End If
    End Function
    End Class

  • Replied 8 September 2017, 4:35 am EST

    Thanks Bob. Works great.


    But for those that are using this code ... just a small note. This code assumes that the checkbox is left justified.


    For my code, I just care for left, center and right so I have the following:


     

    <FONT size=2>

    </FONT><FONT color=#0000ff size=2>if</FONT><FONT size=2> (appearance.HorizontalAlignment == FarPoint.Win.Spread.</FONT><FONT color=#2b91af size=2>CellHorizontalAlignment</FONT><FONT size=2>.Left)


    {


    rectCheck = </FONT><FONT color=#0000ff size=2>new</FONT><FONT size=2> </FONT><FONT color=#2b91af size=2>Rectangle</FONT><FONT size=2>(rc.Left + 2, rc.Top + 2, 14, 14);


    }


    </FONT><FONT color=#0000ff size=2>else</FONT><FONT size=2> </FONT><FONT color=#0000ff size=2>if</FONT><FONT size=2> (appearance.HorizontalAlignment == FarPoint.Win.Spread.</FONT><FONT color=#2b91af size=2>CellHorizontalAlignment</FONT><FONT size=2>.Center)


    {


    rectCheck = </FONT><FONT color=#0000ff size=2>new</FONT><FONT size=2> </FONT><FONT color=#2b91af size=2>Rectangle</FONT><FONT size=2>(rc.Left + rc.Width / 2 - 7, rc.Top + 2, 14, 14);


    }


    </FONT><FONT color=#0000ff size=2>else</FONT><FONT size=2> </FONT><FONT color=#0000ff size=2>if</FONT><FONT size=2> (appearance.HorizontalAlignment == FarPoint.Win.Spread.</FONT><FONT color=#2b91af size=2>CellHorizontalAlignment</FONT><FONT size=2>.Right)


    {


    rectCheck = </FONT><FONT color=#0000ff size=2>new</FONT><FONT size=2> </FONT><FONT color=#2b91af size=2>Rectangle</FONT><FONT size=2>(rc.Right - 16, rc.Top + 2, 14, 14);


    }


    </FONT><FONT color=#0000ff size=2>else

    </FONT><FONT size=2>

    {


    rectCheck = </FONT><FONT color=#0000ff size=2>new</FONT><FONT size=2> </FONT><FONT color=#2b91af size=2>Rectangle</FONT><FONT size=2>(rc.Left + 2, rc.Top + 2, 14, 14);


    }


     


     


    Also, you might want to worry about vertical alignment too.

    </FONT>
  • Replied 8 September 2017, 4:35 am EST

    Loy -

    Nicely done.  Thanks for sharing the code for other users.

Need extra support?

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

Learn More

Forum Channels