假设12个label的TabIndex是从1到13。 int i; string s; for (i = 0;i<Controls.Count;++i) { if (Controls[i].TabIndex >= 1 && Controls[i].TabIndex < 13) { s = Controls[i].Text; } //对s进行处理 }
更安全的写法: if (Controls[i].TabIndex >= 1 && Controls[i].TabIndex < 13 && Controls[i] is Label) {}
可以做个实体类嘛,一个实例保存一条记录的值。 class Record { public string year; public string month; public string decimal; } System.Windows.Forms.Control theCtrl; ArrayList records = new ArrayList(); foreach( theCtrl in form.Controls ) { Record r = new Record(); if( theCtrl.GetType() == TypeOf(System.Windows.Forms.TextBox) ) { if( (TextBox)theCtrl.Name.Substring(6,1) == "Y" ) r.year = theCtrl.Text; else { r.month = theCtrl.Name.Substring(6); r.decimal = theCtrl.Text; } records.Add(r); }}
我凭感觉 JasonHeung() 的方法极具操作性,可我不知从何下手?
数据库字段为 int型 我要更新它 将一个textBox里的值赋给那个字段 怎么写?update 数据库 set 列 = ?????? where ... 关键是那个几个问号?
string s = " update tbl set col = " + textBox1.Text + " where keycol = " + keyvalue;
用户控件可以获取ICommand,当然ICommand是根据每个用户控件实例获取不同的ICommand
。
如果想控件直接操作,用户控件写一个Save方法就可以了。
Form需要多少省个月份,就拖多少个就是了。
在Form直接调用每个控件实例的Sava方法就可以了。
int i;
string s;
for (i = 0;i<Controls.Count;++i)
{
if (Controls[i].TabIndex >= 1 && Controls[i].TabIndex < 13)
{
s = Controls[i].Text;
}
//对s进行处理
}
if (Controls[i].TabIndex >= 1 && Controls[i].TabIndex < 13 && Controls[i] is Label)
{}
class Record
{
public string year;
public string month;
public string decimal;
}
System.Windows.Forms.Control theCtrl;
ArrayList records = new ArrayList();
foreach( theCtrl in form.Controls )
{
Record r = new Record();
if( theCtrl.GetType() == TypeOf(System.Windows.Forms.TextBox) )
{
if( (TextBox)theCtrl.Name.Substring(6,1) == "Y" )
r.year = theCtrl.Text;
else
{
r.month = theCtrl.Name.Substring(6);
r.decimal = theCtrl.Text;
}
records.Add(r);
}}