我正在使用c#,winform创建一个应用程序。
我需要显示表格中的数据,我知道datagridview,我不想使用datagridview显示数据。
表由三个字段ID,名称,地址组成
我想显示如下数据:
编辑按钮应打开另一个面板
教程将有所帮助
我很抱歉,如果已经回答了类似的问题,我搜查了,但无法找到。
Label mLabel = new Label();
private void loadData()
{
int y1 = 0;
mLabel = null;
con = SQLConnec.SQLConnection(); // your sql connection statement
try
{
con.Open();
cmd = new MySqlCommand("SELECT *FROM <table>", con);
dataReader = cmd.ExecuteReader();
while (dataReader.Read())
{
mLabel = new Label();
mLabel.Location = new Point(60, 25 + y1);
mLabel.Text = dataReader.GetString("Name");
mLabel.Font = new Font("Segoe UI Symbol", 18);
mLabel.AutoSize = true;
mLabel.ForeColor = Color.FromArgb(30, 115, 70);
Panel_Detail.Controls.Add(mLabel);
mLabel = new Label();
mLabel.Location = new Point(65, 60 + y1);
mLabel.Font = new Font("Segoe UI Symbol", 11);
mLabel.Text = Regex.Replace(dataReader.GetString("Address"), @"\t|\n|\r", " ");
mLabel.ForeColor = Color.FromArgb(110, 110, 110);
mLabel.AutoSize = true;
Panel_Detail.Controls.Add(mLabel);
mLabel = new Label();
mLabel.Location = new Point(500, 35 + y1);
mLabel.Text = "Edit";
mLabel.Font = new Font("Segoe UI Symbol", 8);
mLabel.AutoSize = true;
mLabel.ForeColor = Color.FromArgb(120, 120, 120);
mLabel.Click += editClick;
mLabel.Name = dataReader.GetString("ID");
Panel_Detail.Controls.Add(mLabel);
y1 = y1 + 90;
}
dataReader.Close();
con.Close();
}
private void editClick(object sender, EventArgs e)
{
//ID is associated with ((Label)sender).name, , you probably could use this to perform your desired operation
}