これは、SqlConnection
を使用してSELECT
コマンドを実行し、必要な行を取得し、行ごとに行の情報を含むカスタムパネルを追加することで実現できます。
またFlowLayoutPanel
、間隔/位置を処理できるようにを使用することをお勧めします。
あなたのForm_Load
:
var conn = new SqlConnection("Your connection informations here");
conn.Open();
var command = new SqlCommand("Select * from YourTable", conn);
using (SqlDataReader reader = command.ExecuteReader())
{
while (reader.Read())
{
// Pass the useful informations to your panel
var pnl = new MyCustomPanel(reader["Id"].ToString(), reader["Property_Type1"].ToString());
flowLayoutPanel1.Controls.Add(pnl);
}
}
conn.Close();
また、カスタムコントロールのコンストラクターは、次のようなものである必要があります。ここでは、各行にパネルのコントロールの値を設定します。
public MyCustomPanel(string id, string propertyType1)
{
txtId.Text = id;
txtPropertyType1.Text = propertyType1;
}
この記事はインターネットから収集されたものであり、転載の際にはソースを示してください。
侵害の場合は、連絡してください[email protected]
コメントを追加