[英]Setting the TabIndex value for a dynamically created textbox
I want to set the tabIndex property for a row of textbox(s) that are created at run time (dynamically) 我想为运行时(动态)创建的一行文本框设置tabIndex属性
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'. 当我尝试对此进行编译时,出现错误无法将类型'int'隐式转换为'short'。 An explicit conversion exists (are you missing a cast?)
存在显式转换(您是否缺少演员表?)
Any ideas? 有任何想法吗?
txtFirstName.TabIndex = (short)(i * 10 + 1);
You could try 你可以试试
System.Convert.ToInt16( value );
for each property set 对于每个属性集
I is most likely defined as an int. 我很可能被定义为一个int。 Multiplying an int by a literal results in an int by default.
默认情况下,将int与文字乘以一个int。 You can cast ie tell this is another type using the (Type) cast expression.
您可以使用(Type)强制转换表达式进行强制转换,即告诉这是另一种类型。
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. Tabindex很短,因此您必须强制转换。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.