Setting focus

P

paulotuatail

Hi I have a windows form with lots of text boxes and a button. These are in3 group boxes. One text box has the focus for no apparent reason. I have googled this but can't find a solution there. I realised that I can acheve this by changing the tab order. In one group box I have 2 text boxes with the same tab index. How? In VB 6 any atempt to change a tab index that conflicted would mave the other changed.

Having renumberd the tab index. I find a difrent text box now has the focusbut not tab index 1. To make things worse the 3 group boxes have tab index14,15 and 16 which dublicate 3 tab indexes of 3 text boxes.

I initialy tried this without success.

public partial class Tax : Form
{
Double Wage = 181.00;
Double Wage_M;
Double LowerPrimary = 109;
Double UpperPrimary = 797;
Double PrimaryThreshold = 149.00;
Double Allowance = 9400;
Double WeekAlowance;
Double TaxRate = 20;
Double NIrate = 12;


public Tax()
{
InitializeComponent();
This line added here -> txtWage.Focus();
txtWage.Text = String.Format("{0:n2}", Wage);
txtLE.Text = String.Format("{0:n2}", LowerPrimary);
txtUE.Text = String.Format("{0:n2}", UpperPrimary);
txtPT.Text = String.Format("{0:n2}", PrimaryThreshold);
txtER.Text = String.Format("{0:n0}", NIrate);
txtAllowance.Text = String.Format("{0:n2}", Allowance);
txtRate.Text = String.Format("{0:n0}", TaxRate);
}

Any ideas as I have searched for this on line.

Desmond.
 
P

paulotuatail

Hi I have a windows form with lots of text boxes and a button. These are in 3 group boxes. One text box has the focus for no apparent reason. I havegoogled this but can't find a solution there. I realised that I can achevethis by changing the tab order. In one group box I have 2 text boxes with the same tab index. How? In VB 6 any atempt to change a tab index that conflicted would mave the other changed.



Having renumberd the tab index. I find a difrent text box now has the focus but not tab index 1. To make things worse the 3 group boxes have tab index 14,15 and 16 which dublicate 3 tab indexes of 3 text boxes.



I initialy tried this without success.



public partial class Tax : Form

{

Double Wage = 181.00;

Double Wage_M;

Double LowerPrimary = 109;

Double UpperPrimary = 797;

Double PrimaryThreshold = 149.00;

Double Allowance = 9400;

Double WeekAlowance;

Double TaxRate = 20;

Double NIrate = 12;





public Tax()

{

InitializeComponent();

This line added here -> txtWage.Focus();

txtWage.Text = String.Format("{0:n2}", Wage);

txtLE.Text = String.Format("{0:n2}", LowerPrimary);

txtUE.Text = String.Format("{0:n2}", UpperPrimary);

txtPT.Text = String.Format("{0:n2}", PrimaryThreshold);

txtER.Text = String.Format("{0:n0}", NIrate);

txtAllowance.Text = String.Format("{0:n2}", Allowance);

txtRate.Text = String.Format("{0:n0}", TaxRate);

}



Any ideas as I have searched for this on line.



Desmond.

Ok I don't know how I have worked this out but here goes.

I have 3 group boxes from left to right. I have 6 txt's in the far right group box. Both have indes 14 and are the lowest index in that group. The onehalf way down is the duplicate and lowest tab value. This is the one beingpicked. Also this group box has the lowest group number.

When I renumbered the txt controls the top one on the far right group took over the focus. Now renumbering the groyp boxes from left to right 1 2 and 3 it finaly works.

It seems it lookes for the lowest tabed group box then for the lowest tab index in the group. If there there is a duplicate (which should not be allowed) it picks the latter of the 2.

This is very strange behaviour. Any input on this PLEASE.

Desmond.
 
J

Jeff Johnson

Hi I have a windows form with lots of text boxes and a button. These are
in 3 group boxes. One
text box has the focus for no apparent reason. I have googled this but
can't find a solution there.
I realised that I can acheve this by changing the tab order.

How did you change the tab order? Did you use the toolbar button in the IDE
and then click on the controls in the order that you want them to have focus
or did you just start changing TabIndexes in the Properties window?
 
Top