双击Datagridview,在新表单的文本框中显示
问题描述:
美好的一天
我创建了一个C#windows应用程序。在C#windows应用程序中,我创建了一个带有datagridview的表单。数据显示在datagridview内的数据库中。
所有数据都显示在一个简短的过程中。它正在100%工作。
我想在datagridview中双击并显示我在新表单上双击文本框的行。
有什么建议吗?
谢谢
Good day
I have created a C# windows application. In the C# windows application I have created a form with a datagridview on it. The data is displayed from a database inside the datagridview.
All the data is displayed from a short proc. It is working 100%.
I want to double click in the datagridview and display the row that I have double clicked in textboxes on a new form.
Any suggestions?
Thanks
答
你好,
我希望它有所帮助:
以下代码生成一个Winform
以及一些动态的TextBox
。
Hello,
I hope it helps:
Following code generates a "Winform
" and a number of "TextBox
"es dynamically.
private void MyGrid_DoubleClick(object sender, EventArgs e)
{
if (this.MyGrid.SelectedRows.Count == 0)
return;
System.Windows.Forms.Form form = new Form();
int count = 0;
foreach (DataGridViewCell cell in this.MyGrid.SelectedRows[0].Cells)
{
string value = cell.Value == null ? string.Empty : cell.Value.ToString();
TextBox textBox = new TextBox()
{
Text = value,
Top = 27 * count + 10
};
form.Controls.Add(textBox);
count++;
}
form.Height = (count + 1) * 37;
form.Show();
}
您好JacoBosch,
按照以下步骤操作可能会对您有所帮助。
1.在你要打开的表格中声明一个构造函数和一个公共变量。
Hi JacoBosch,
Follow this steps it may help you.
1. declare a constructor and a public variable in the form which you want to open.
public string strvalue = string.Empty;
public Form2()
{
InitializeComponent();
}
public Form2(string str)
{
strvalue = str;
InitializeComponent();
}
2.打开这样的表格2
2.Open form2 like this
private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e)
{
if (e.RowIndex != -1)
{
if (e.ColumnIndex != 1)
{
if (!string.IsNullOrEmpty(dataGridView1.Rows[e.RowIndex].Cells[e.ColumnIndex].Value.ToString()))
{
string strValue = dataGridView1.Rows[e.RowIndex].Cells[e.ColumnIndex].Value.ToString();
Form2 _Form2 = new Form2(strValue);
_Form2.ShowDialog();
dataGridView1.Rows[e.RowIndex].Cells[e.ColumnIndex].Value = _Form2.strvalue;
dataGridView1.Refresh();
}
}
}
}
3.关闭事件上的form2并设置值
3. Close form2 on a event and set value in
private void button1_Click(object sender, EventArgs e)
{
strvalue = textBox1.Text;
this.Close();
}
我想修复解决方案2
第3步:
private void form2_load(object sender,EventArgs e)
{
textBox.Text = strvalue;
}
i want to fix SOLUTION 2
STEP 3:
private void form2_load (object sender ,EventArgs e)
{
textBox.Text=strvalue;
}