Basic4ppc - Windows Mobile Development  

Go Back   Basic4ppc - Windows Mobile Development > Main Category > Questions & Help Needed
Home Register FAQ Members List Search Today's Posts Mark Forums Read

Questions & Help Needed Post any question regarding Basic4ppc.


Unwanted Click Event


Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 05-05-2008, 01:14 AM
Knows the basics
 
Join Date: May 2008
Location: Newcastle Upon Tyne - England
Posts: 57
Default Unwanted Click Event

Please allow me to introduce myself. I stumbled across B4P as I've been trying to learn languages such as Visual C++ etc. I learn best by having a full syntax of commands and some good examples where I can substitute my own code.

My previous experience of coding is Psion OPL, HD6303X assembler (for PSION Org2) and various other 'Basic' type languages.

I have fully registered for B4P and I'd welcome some help for some code as attached. I'm asking a series of questions - six in this case - and want the user to select their answer with a radio button, then move on to the next question. Before submitting, I'd like them to be able to review their answers and change. You'll see it populates an array Answer(). Going forward works fine, going back works fine too, until the transition between Q2 and Q1. Q1 takes on the answer from Q2, but only if Q2 has been answered. By using breakpoints and adding some tracing code, I see for some reason when hitting 'Prev' when on Q2 wishing to go to Q1, the Radio_Click Sub is invoked, populating Q1 with Q2s answer. But only if Q2 has been answered.

I've stripped out all my other code to keep it clear.
Attached Files
File Type: sbp Question Example.sbp (1.8 KB, 7 views)
Reply With Quote
  #2 (permalink)  
Old 05-05-2008, 06:35 AM
Erel's Avatar
Administrator
 
Join Date: Apr 2007
Posts: 3,335
Default

I'm not sure if it is a bug in the .Net Framework or an intended behavior, but when a RadioBtn is focused it also gets selected (or clicked).
When you disable prevBtn the focus moves to the RadioBtn.
You should move the focus to nextBtn and it will be fixed:
Code:
Sub ShowData
    If AnsRec=0 Then
        NextBtn.Focus
        PrevBtn.Enabled=False
        NextBtn.Enabled=True
    Else If AnsRec=5 Then
Reply With Quote
  #3 (permalink)  
Old 05-05-2008, 02:39 PM
klaus's Avatar
Basic4ppc Expert
 
Join Date: Oct 2007
Location: Switzerland
Posts: 819
Awards Showcase
Beta Tester Competition Winner 
Total Awards: 2
Default

Erel,
This behaviour looks strange.

I renamed PrevBtn to PrevBtn1
I added a new button named it PrevBtn
Deleted button PrevBtn1
Renamed Sub PrevBtn1 back to Sub PrevBtn
And it works normally. Source QuestionExampleNew
in this code when PrevBtn.Enabled=False is executed,
the Radio_Click routine is not called.

I also tried the following code
in this code when PrevBtn.Enabled=False is executed,
the Sender in the Radio_Click routine is RadioButton1

Code:
Sub ShowData
  Label1.Text="Q"&(AnsRec+1)&". "
  If Answer(AnsRec)=0 Then
    For i=1 To 5
      Control("RadioBtn"&i).Checked=False
    Next
  Else
  Control("RadioBtn"&Answer(AnsRec)).Checked=True
  End If
  If AnsRec=0 Then
    PrevBtn.Enabled=False
    NextBtn.Enabled=True
  Else If AnsRec=5 Then
    PrevBtn.Enabled=True
    NextBtn.Enabled=False
  Else
    PrevBtn.Enabled=True
    NextBtn.Enabled=True
  End If
End Sub
instead of

Code:
Sub ShowData
  If AnsRec=0 Then
    PrevBtn.Enabled=False
    NextBtn.Enabled=True
  Else If AnsRec=5 Then
    PrevBtn.Enabled=True
    NextBtn.Enabled=False
  Else
    PrevBtn.Enabled=True
    NextBtn.Enabled=True
  End If
  Label1.Text="Q"&(AnsRec+1)&". "
  If Answer(AnsRec)=0 Then
    For i=1 To 5
      Control("RadioBtn"&i).Checked=False
    Next
  Else
  Control("RadioBtn"&Answer(AnsRec)).Checked=True
  End If
End Sub
in this code when PrevBtn.Enabled=False is executed,
the Sender in the Radio_Click routine is RadioButton2 which gives the wrong information.

Best regards
Attached Files
File Type: sbp Question ExampleNew.sbp (1.8 KB, 2 views)
__________________
Klaus
Switzerland
Reply With Quote
  #4 (permalink)  
Old 05-05-2008, 03:04 PM
Knows the basics
 
Join Date: May 2008
Location: Newcastle Upon Tyne - England
Posts: 57
Default

Many thanks Erel, that has enabled that Sub to execute as I had intended.

Klaus, from my understanding, the Radio_Click event is inadvertantly triggered when focus is shifted to the radio button. A bit like on desktop applications, when you press the <TAB> key; there is an order to which each control is focussed with the <TAB> (In visual C++ the programmer may define this sequence.) In my case, when the 'Prev' button was disabled, the next control in order was the Radio. This then generated the Radio_Click and wrongly populated the array. In your attached code, because you have moved things around, the unwanted event moves to the end; i.e. when you click the final 'Next' the last question is populated from the unwanted event. Again this is cured by shifting focus to the 'Prev' button before disabling 'Next'

(I'm learning quickly...)
Reply With Quote
  #5 (permalink)  
Old 05-05-2008, 03:12 PM
agraham's Avatar
Basic4ppc Expert
 
Join Date: Jul 2007
Location: Cheshire, UK
Posts: 1,900
Awards Showcase
Beta Tester Forum Contributer 
Total Awards: 2
Default

It works fine for me if you move the button enabling/disabling code after the radio button setting but I'm not sure why.

Code:
Sub ShowData
	Label1.Text="Q"&(AnsRec+1)&". "
	If Answer(AnsRec)=0 Then
		For i=1 To 5
			Control("RadioBtn"&i).Checked=False
		Next
	Else
		Control("RadioBtn"&Answer(AnsRec)).Checked=True
	End If
	If AnsRec=0 Then
		PrevBtn.Enabled=False
		NextBtn.Enabled=True
	Else If AnsRec=5 Then
		PrevBtn.Enabled=True
		NextBtn.Enabled=False
	Else
		PrevBtn.Enabled=True
		NextBtn.Enabled=True
	End If	
End Sub
EDIT : Got it! I didn't originally get the full import of Erel's explanation. Disabling the Prev button causes the focus to move from the Prev button back to the Radio Button. However AnsRec has already been decremented so Radio_Click thinks this extra click it is a new value for Q1 and stores what was the value for Q2 as Q1's value overwriting the previous value. Putting the disabling later ensures that the correct Radio Button for Q1 has already been selected so that it still overwrites the answer, but with the correct one this time!

Last edited by agraham : 05-05-2008 at 03:38 PM.
Reply With Quote
  #6 (permalink)  
Old 05-05-2008, 10:17 PM
klaus's Avatar
Basic4ppc Expert
 
Join Date: Oct 2007
Location: Switzerland
Posts: 819
Awards Showcase
Beta Tester Competition Winner 
Total Awards: 2
Default

My post was not really clear, I didn't mention that for me the code with the Enabled=false at the end works OK also.
But for me it is still strange that the last RadioButton that had the focus is triggered when the PrevBtn.Enabled=false and this behaviour depends on the order we enter the buttons. If the buttons are entered in a different order the program has a 'normal' behaviour ! ?

Best regards
__________________
Klaus
Switzerland
Reply With Quote
  #7 (permalink)  
Old 05-06-2008, 06:25 AM
Erel's Avatar
Administrator
 
Join Date: Apr 2007
Posts: 3,335
Default

When the button is disabled the focus moves to the "next" control.
Depending on the order you've added the controls the next control can be a different control.
You can change the order of controls by using this method: Tab Order for Controls
Reply With Quote
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Similar Threads
Thread Thread Starter Forum Replies Last Post
event doubleclick and click on the cell (table object)... micro Questions & Help Needed 2 08-19-2008 06:50 PM
Right Click ?? pegamaster Questions & Help Needed 2 07-07-2008 07:11 PM
Click event during a for loop pmu5757 Questions & Help Needed 7 04-12-2008 04:44 PM
TreeView Click Event RandomCoder Basic4ppc Wishlist 5 02-28-2008 04:23 PM
Click function neilnapier Questions & Help Needed 12 11-03-2007 07:51 PM


All times are GMT. The time now is 07:52 PM.


Powered by vBulletin® Version 3.6.12
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.1.0