簡體   English   中英

如何將數據從datagridview單元傳輸到並標記?

[英]How to transfer data from datagridview cell to and label?

我的學校項目中有兩個Forms,想法是,當我雙擊DataGridView行(在Form1中)進入Form2時,我的標簽為空,需要將它們設置為等於其中的數據。我雙擊該行的單元格。 DataGridView是從MySql Server表填充的。

    private void dataGridView1_CellMouseDoubleClick(object sender, DataGridViewCellMouseEventArgs e)
    {
        DataGridViewRow row = this.dataGridView1.Rows[e.RowIndex];
        //populate the textbox from specific value of the coordinates of column and row.
        Form2.label1.Text = row.Cells[0].Value.ToString();
        Form2.label2.Text = row.Cells[1].Value.ToString();
        Form2.label3.Text = row.Cells[2].Value.ToString();
        Form2.label4.Text = row.Cells[3].Value.ToString();
        Form2.label5.Text = row.Cells[4].Value.ToString();
        Form2.label6.Text = row.Cells[6].Value.ToString();
        Form2.label7.Text = row.Cells[7].Value.ToString();
        Form2.label8.Text = row.Cells[8].Value.ToString();
        Form2.label9.Text = row.Cells[9].Value.ToString();
        Form2.label10.Text = row.Cells[10].Value.ToString();
        Form2.label11.Text = row.Cells[11].Value.ToString();
        Form2.label12.Text = row.Cells[12].Value.ToString();
        Form2.label13.Text = row.Cells[13].Value.ToString();
        Form2.label14.Text = row.Cells[14].Value.ToString();
    }

我試過這樣,但是它不起作用,它報告標簽錯誤,不知道如何在這種交叉表單上進行這項工作?

我剛剛創建了一個樣本,您可以這樣做

 Form2 form2 = new Form2();
            DataGridViewRow row = this.dataGridView1.Rows[e.RowIndex];
            //populate the textbox from specific value of the coordinates of column and row.
            form2.label1.Text = row.Cells[0].Value.ToString();
            form2.Show();

在Form2.Designer中,您從私有更改為公共

public System.Windows.Forms.Label label1;

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM