C# ,load事件加载了多个控件。现在想在另一个事件Click中读取并修改这些控件。
publicvoidbatchscanningfeelsize_Load(objectsender,EventArgse){SqlConnectionsconn=newS...
public void batchscanningfeelsize_Load(object sender, EventArgs e) {
SqlConnection sconn = new SqlConnection("Server=" + _sysip + "\\xxf;Integrated Security= false;Database=xxb;uid = xxx;pwd =xxxx");
SqlCommand scmd = new SqlCommand("select * from nodedatasource order by id", sconn);
sconn.Open();
SqlDataReader sdrr = scmd.ExecuteReader();
DataTable dt = new DataTable();
dt.Load(sdrr);
sconn.Close();
for (int i = 0; i <= dt.Rows.Count-1; i++) {
wxControl1 wxctl = new wxControl1();
System.Drawing.Point p = new Point(5, 5 + i * 20);
wxctl.Location = p;
panel1.Controls.Add(wxctl);
wxsz[1, i] = dt.Rows[i]["code"].ToString();
wxctl._nodecode.Text = wxsz[1, i] ;
wxctl._nodename.Text = dt.Rows[i]["name"].ToString();
wxctl._nodeip.Text = dt.Rows[i]["name"].ToString();
wxctl._pingresult.Text = "未知";
wxctl._RunStatus.Text = "未知";
wxctl._disk.Text = "未知";
wxctl._feelsize.Text = "未知";
wxctl.Name = "wxctl" + i;
string cptpwd = dt.Rows[i]["cptpwd"].ToString();
}
dt.Clear();
}
private void button2_Click(object sender, EventArgs e) {
}
//load时加载了一些控件。在Click事件时,我想更改根据每一个控件的_nodeip等等、改变该控件的其他(比如:_feelsize)。 展开
SqlConnection sconn = new SqlConnection("Server=" + _sysip + "\\xxf;Integrated Security= false;Database=xxb;uid = xxx;pwd =xxxx");
SqlCommand scmd = new SqlCommand("select * from nodedatasource order by id", sconn);
sconn.Open();
SqlDataReader sdrr = scmd.ExecuteReader();
DataTable dt = new DataTable();
dt.Load(sdrr);
sconn.Close();
for (int i = 0; i <= dt.Rows.Count-1; i++) {
wxControl1 wxctl = new wxControl1();
System.Drawing.Point p = new Point(5, 5 + i * 20);
wxctl.Location = p;
panel1.Controls.Add(wxctl);
wxsz[1, i] = dt.Rows[i]["code"].ToString();
wxctl._nodecode.Text = wxsz[1, i] ;
wxctl._nodename.Text = dt.Rows[i]["name"].ToString();
wxctl._nodeip.Text = dt.Rows[i]["name"].ToString();
wxctl._pingresult.Text = "未知";
wxctl._RunStatus.Text = "未知";
wxctl._disk.Text = "未知";
wxctl._feelsize.Text = "未知";
wxctl.Name = "wxctl" + i;
string cptpwd = dt.Rows[i]["cptpwd"].ToString();
}
dt.Clear();
}
private void button2_Click(object sender, EventArgs e) {
}
//load时加载了一些控件。在Click事件时,我想更改根据每一个控件的_nodeip等等、改变该控件的其他(比如:_feelsize)。 展开
1个回答
展开全部
List<wxControl1> list_wx=new List<wxControl1>(); //新增
public void batchscanningfeelsize_Load(object sender, EventArgs e)
for (int i = 0; i <= dt.Rows.Count-1; i++)
list_wx.Clear(); //新增
for (int i = 0; i <= dt.Rows.Count-1; i++) {
wxControl1 wxctl = new wxControl1();
list_wx.add(wxctl);
之后就可以在其它控件访问
for(int i=0;i<list_wx.Count;i++)
// list_wx[i]._nodeip
public void batchscanningfeelsize_Load(object sender, EventArgs e)
for (int i = 0; i <= dt.Rows.Count-1; i++)
list_wx.Clear(); //新增
for (int i = 0; i <= dt.Rows.Count-1; i++) {
wxControl1 wxctl = new wxControl1();
list_wx.add(wxctl);
之后就可以在其它控件访问
for(int i=0;i<list_wx.Count;i++)
// list_wx[i]._nodeip
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询