我需要在表格中顯示檢查結果,假設我對一個結果應該在第一行表格佈局面板中顯示的紙張進行了測試,並且if我採取一個更紙測試結果應該是在表佈局面板的第二行顯示動態使用C#(如果我在結果存儲按鈕點擊它應該重定向到測試結果表格並顯示結果)如何在窗體中動態地將數據插入表格
public partial class Form3 : Form
{
private string papId;
private string subject;
private string chapter;
private string tstname;
public Form3(string papId,string tech,string subject,string chapter, string tstname,int maxMarks,int marksObtained)
{
InitializeComponent();
this.papId=papId;
this.subject=subject ;
this.chapter = chapter;
this.tstname = tstname;
int row = dsplyUserReslt.Count;
Label lblTech = getLabelDetails();
lblTech.Text = tech;
dsplyUserReslt.Controls.Add(lblTech, 0, row-1);
Label lblSub = getLabelDetails();
lblSub.Text = subject;
dsplyUserReslt.Controls.Add(lblSub,1, row-1);
Label lblChptr = getLabelDetails();
lblChptr.Text = chapter;
dsplyUserReslt.Controls.Add(lblChptr, 2, row-1);
Label lbltstName = getLabelDetails();
lbltstName.Text = tstname;
dsplyUserReslt.Controls.Add(lbltstName, 3, row-1);
Label lblmaxmarks = getLabelDetails();
lblmaxmarks.Text = maxMarks.ToString();
dsplyUserReslt.Controls.Add(lblmaxmarks, 4, row-1);
Label lblmarksobtnd = getLabelDetails();
lblmarksobtnd.Text = marksObtained.ToString();
dsplyUserReslt.Controls.Add(lblmarksobtnd, 5, row - 1);
Label date = getLabelDetails();
date.Text = DateTime.Now.ToString("MMMM dd, yyyy");
dsplyUserReslt.Controls.Add(date, 6, row - 1);
Button btnImproveScore = new Button();
btnImproveScore.Text = "improve score";
btnImproveScore.Size = new System.Drawing.Size(135, 25);
btnImproveScore.Font = new Font("Microsoft Sans Serif", 10);
dsplyUserReslt.Controls.Add(btnImproveScore, 7, row - 1);
btnImproveScore.Click+=new EventHandler(this.btnImproveScore_Click);
if (row > 4)
{ dsplyUserReslt.RowCount = 4; }
else
{
dsplyUserReslt.RowCount = dsplyUserReslt.RowCount + 1;
dsplyUserReslt.RowStyles.Clear();
dsplyUserReslt.RowStyles.Add(new RowStyle(SizeType.Absolute, 120F));
}
}
public Label getLabelDetails()
{
Label lbl = new Label();
lbl.AutoSize = true;
lbl.Font = new Font("Microsoft Sans Serif", 12);
lbl.TextAlign = System.Drawing.ContentAlignment.MiddleLeft;
return lbl;
}
,並在你的代碼?你試過什麼了? – Marusyk
SO不是一個軟件寫作服務......毫無疑問,這個問題將在適當的時候關閉。 –
@MegaTron我把tabel佈局面板當作dsplyUsrReslt,並且最初它的行數是1.現在我的問題是如果我再次進行測試意味着它重新定向並且它正在顯示行計數值1 –