开发者

Setting the TabIndex value for a dynamically created textbox

开发者 https://www.devze.com 2022-12-21 04:35 出处:网络
I want to set the tabIndex property for a row of textbox(s) that are created at run time (dynamically)

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;

Wh开发者_JAVA技巧en 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?


You could try

System.Convert.ToInt16( value );

for each property set


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.


txtFirstName.TabIndex = (short)(i * 10 + 1);
0

精彩评论

暂无评论...
验证码 换一张
取 消