tags:

views:

181

answers:

2

I want to set the tabIndex property for a row of textbox(s) that are created at run time (dynamically)

My formula is

txtFirstName.TabIndex = i * 10 + 1;
txtLastName.TabIndex = i * 10 + 2;
txtEMail.TabIndex = i * 10 + 3;
txtPhone.TabIndex = i * 10 + 4;

When I try to compile this, I get an error Cannot implicitly convert type 'int' to 'short'. An explicit conversion exists (are you missing a cast?)

Any ideas?

+1  A: 

You could try

System.Convert.ToInt16( value );

for each property set

JDMX
Thanks for your help !!
user279521
+1  A: 

I is most likely defined as an int. Multiplying an int by a literal results in an int by default. You can cast ie tell this is another type using the (Type) cast expression.

int I = 5 ; 
short X ; 
X = I; //Error 
I = X; //fine I is larger then X so an implicit cast happens 
X = (short)I ; //also fine

Tabindex is a short so you will have to cast.

rerun