Posted 8 September 2017, 1:08 pm EST<P>I have two comboboxes and a spread on my control. The spread is databound. If a cell in the spread has an error then a property is set for the spread. If that property is true and a user tries to click off of the spread then I want to prevent them from doing this. I have tried the Leave event of the spread but that does not seem to fire when I click off of the spread. Any ideas would be great. Thanks.</P>
Remove focus from Spread
Posted by: sameek on 8 September 2017, 1:08 pm EST
Replied 8 September 2017, 1:08 pm ESTmmeek -<br><br>If you use the LeaveCell event and check the validation of the cell then you should be able to set the e.Cancel in the event to true. Have you tried that? If so, can you post a small project reproducing this for us to debug.<br>
Replied 8 September 2017, 1:08 pm ESTYes, I have e.cancel in the LeaveCell event, and while that does prevent you from leaving the cell on the spread, it does allow you to move off of the spread and do other things. I was thinking that there may be a way to prevent them from leaving the spread?
Replied 8 September 2017, 1:08 pm EST<P>Hello,</P>
<P>You need to use the Validating event to keep focus from leaving a control.</P> <PRE class=coloredcode> <SPAN class=kwd>Private Sub</SPAN> FpSpread1_Validating(<SPAN class=kwd>ByVal</SPAN> sender <SPAN class=kwd>As Object</SPAN>, <SPAN class=kwd>ByVal</SPAN> e <SPAN class=kwd>As</SPAN> System.ComponentModel.CancelEventArgs) <SPAN class=kwd>Handles</SPAN> FpSpread1.Validating
e.Cancel = <SPAN class=kwd>True