1
我想傳遞datagridview的當前行的列值。我在datagridview中的一列上有一個按鈕。當我點擊按鈕時,另一個窗體打開。我在另一個表單上有一個文本框。所以我想在另一個表單的文本框中獲取當前行的列值。我正在使用c sharp。我想將datagrid視圖的當前行的特定列值存入另一個表單的文本框中。我該怎麼做。我正在使用c sharp
任何幫助表示讚賞。
我想傳遞datagridview的當前行的列值。我在datagridview中的一列上有一個按鈕。當我點擊按鈕時,另一個窗體打開。我在另一個表單上有一個文本框。所以我想在另一個表單的文本框中獲取當前行的列值。我正在使用c sharp。我想將datagrid視圖的當前行的特定列值存入另一個表單的文本框中。我該怎麼做。我正在使用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;
}
}
謝謝。欣賞它 – user286546
你是如何打開新的形式? – kiev