그래픽 종류의 SQL 편집기를 만들려고합니다. 그러나 표의 비주얼이 마음에 들지 않아 더 많이 추가하려고합니다. 상호 작용 (드래그/드롭 등).C# Windows Form : 반복적으로 생성 된 텍스트 상자를 반복하고 텍스트가 변경되었는지 확인합니다.
각 레코드를 기반으로 패널을 작성하고 테이블의 각 레코드를 기반으로 각 패널에 텍스트 상자를 추가했습니다. 지금 당장 붙어있는 것은 동적으로 생성 된 컨트롤을 반복하고 해당 상태를 확인하거나 상호 작용하는 개념입니다.
내가 구조화하는 방법에 문제가 있으면 알려주십시오.
private void comboBox1_SelectedIndexChanged_1(object sender, EventArgs e)
{
groupBox1.Controls.Clear();
string pDBString = null;
SqlConnection cnn;
pDBString = "Data Source=localhost\\" + Form1.host + ";Initial Catalog=" + Form1.db + ";Integrated Security=SSPI;";
cnn = new SqlConnection(pDBString);
string sqlForProps = "select * from PROPS where user_id_txt ='" + comboBox1.SelectedItem.ToString() + "'";
try
{
using (cnn)
{
cnn.Open();
SqlCommand cmd = new SqlCommand(sqlForProps, cnn);
SqlDataReader sqlReader = cmd.ExecuteReader();
int x = 0;
int count = 0;
while (sqlReader.Read())
{
Panel panel = new System.Windows.Forms.Panel();
panel.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D;
x += 30;
panel.Location = new System.Drawing.Point(3, x);
panel.Name = "panel" + count;
panel.Size = new System.Drawing.Size(519, 30);
panel.TabIndex = 3;
PropsPanels.Add(panel);
groupBox1.Controls.Add(panel);
TextBox textbox = new System.Windows.Forms.TextBox();
panel.Controls.Add(textbox);
textbox.Location = new System.Drawing.Point(1, 3);
textbox.Name = "textBox" + count;
textbox.Size = new System.Drawing.Size(100, 20);
textbox.TabIndex = 4;
textbox.Text = sqlReader["USER_ID_TXT"].ToString();
TextBox textboxAM = new System.Windows.Forms.TextBox();
panel.Controls.Add(textboxAM);
textboxAM.Location = new System.Drawing.Point(126, 3);
textboxAM.Name = "textBoxAM" + count;
textboxAM.Size = new System.Drawing.Size(100, 20);
textboxAM.TabIndex = 4;
textboxAM.Text = sqlReader["PROP_TXT"].ToString();
TextBox textboxAMSet = new System.Windows.Forms.TextBox();
panel.Controls.Add(textboxAMSet);
textboxAMSet.Location = new System.Drawing.Point(232, 3);
textboxAMSet.Name = "textBoxAM" + count;
textboxAMSet.Size = new System.Drawing.Size(100, 20);
textboxAMSet.TabIndex = 4;
textboxAMSet.Text = sqlReader["VAL_TXT"].ToString();
count++;
}
sqlReader.Close();
cnn.Close();
}
}
catch (Exception ex)
{
MessageBox.Show("Can not open connection !");
}
}
패널을 점검 할 생각되는 코드 : : 예를 들어
public AMMain()
{
InitializeComponent();
string pDBString = null;
SqlConnection cnn;
pDBString = "Data Source=US7-AHACKETT\\SQLEXPRESS;Initial Catalog=OrchestroConfigurationDB;Integrated Security=SSPI;";
MessageBox.Show(pDBString);
cnn = new SqlConnection(pDBString);
try
{
using (cnn)
{
SqlCommand sqlForUserList = new SqlCommand("select UserName from users a join Company b on a.CompanyID = b.CompanyID where CompanyCode='" + Form1.company + "'", cnn);
cnn.Open();
MessageBox.Show("Connection Open !");
SqlDataReader sqlReader = sqlForUserList.ExecuteReader();
while (sqlReader.Read())
{
comboBox1.Items.Add(sqlReader["UserName"].ToString());
}
sqlReader.Close();
cnn.Close();
}
}
catch (Exception ex)
{
MessageBox.Show("Can not open connection !");
}
foreach (Panel p in PropsPanels)
{
foreach (Control c in p.Controls)
{
if(c is TextBox)
{
object sender = new object();
EventArgs e = new EventArgs();
if(c.TextChanged()??????)
{
//DOSOMETHING
}
}
}
}
}
: 패널을 생성
코드를 다음과 같이
내 코드 인 경우 I 양식에 입력 한 텍스트 상자에서 텍스트가 변경되었는지 확인하고 싶습니다.
private void textBox1_TextChanged(object sender, EventArgs e)
{
}
그래서 런타임에 Textbox를 생성 할 때 런타임에이를 확인하는 방법에 대해 머리를 감쌀 수 없습니다.
도움 주셔서 감사합니다. 예를 들어
'comboBox1_SelectedIndexChanged_1' 메소드에서 텍스트 상자를 생성 할 때 해당 텍스트 상자의 TextChanged 매개 변수에 이벤트 핸들러를 할당하십시오. I.E :'textbox.TextChanged + = myEventHandler; ' –