在C#Windows环境中通过sqlserver创建动态控件. [英] create dynamic controls through sqlserver in C# windows environment.
问题描述
您能否在C#Windows环境中通过sqlserver编写代码来帮助我创建动态控件.
必须将eg:combobox控件用作表类型或sqlserver中的列,并在Windows窗体中生成.
问候
Hariharan.S
Hi,
Could you please help me with the code to create dynamic controls through sqlserver in C# windows environment.
Have to use controls for eg:combobox as table type or column in sqlserver and generate in the windows forms.
Regards
Hariharan.S
推荐答案
您的问题并没有确切说明您想做什么.您是说要创建SQL查询指定的控件吗?如果是这样,您将必须执行以下操作:
Your question doesn''t exactly spell out what you want to do. Are you saying you want to create controls as specified from a SQL query? If so, you would have to do something like this:
// assuming you've already retrieved your sql data into a DataTable object:
bool haveCtrl = true;
DataRow row = datatable.Rows[0];
switch (row["ControleType"].Value.ToLower())
{
case "combobox" :
{
ComboBox ctrl = new ComboBox();
ctrl.Name = row["CtrlID"].Value;
ctrl.Location = new Location(Convert.ToInt32(row["CtrlXPos"].Value), Convert.ToInt32(row["CtrlYPos"].Value));
ctrl.Width = Convert.ToInt(row["CtrlWidth"].Value);
ctrl.Height = Convert.ToInt(row["CtrlHeight"].Value);
//... continue setting properties specified by the data retrieved (or static values)
}
break;
case "textbox" :
{
// ... blah blah blah
}
break;
default :
haveCtrl = false;
break;
}
this.Controls.Add(ctrl);
您确定要这样做吗?如果您要基于要使用的数据添加控件,那么我将创建适当数量的UserControl
对象,然后仅添加适合于将要操作的数据的对象. .
Are you really sure you want to do that? If you''re adding controls based on the data you''re going to be using, I would create an appropriate number of UserControl
objects and just add the one that is appropriate for the data that''s going to be manipulated.
这篇关于在C#Windows环境中通过sqlserver创建动态控件.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!