簡體   English   中英

我想將datagrid視圖的當前行的特定列值放入另一種形式的文本框中。 我該怎么做。 我正在使用C Sharp

[英]I want to get the particular column value of the current row of the datagrid view into text box of another form. How can I do it. I am using c sharp

我想傳遞datagridview當前行的列值。 我在datagridview的一列上有一個按鈕。 當我單擊按鈕時,將打開另一個表格。 我在另一個表格上有一個文本框。 所以我想在另一種形式的文本框中獲取當前行的列值。 我正在使用c Sharp。

任何幫助表示贊賞。

這是使用構造函數接收值的示例:

public partial class Form1 : Form
{
    public Form1()
    {
        InitializeComponent();

    }

    private void Form1_Load(object sender, EventArgs e)
    {
        //test data
        this.dataGridView1.Rows.Add(1);
        this.dataGridView1[1, 0].Value = "testValue1";
        this.dataGridView1[1, 1].Value = "testValue2";
    }

    private void dataGridView1_CellClick(object sender, DataGridViewCellEventArgs e)
    {
        //Button is in column 0.
        if ((e.ColumnIndex != 0) || (e.RowIndex < 0)) { return; }


        string valueToPass = (dataGridView1[1, e.RowIndex].Value as string) ?? String.Empty;
        Form2 f2 = new Form2(valueToPass);
        f2.Show();
    }

}


public partial class Form2 : Form
{
    public Form2(string valueFromOtherForm)
    {
        InitializeComponent();
        this.textBox1.Text = valueFromOtherForm;
    }

}

暫無
暫無

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

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