[英]datagridview in c# windows forms application
I'm working on DataGridView
in C# WindowsForms
application using SQL server 2005 and i added 1 column ie "name" to my DataGridView
and displayed it by selecting row to text box but it shows only one column ie "Name" to text box.我正在使用 SQL server 2005 在 C#
WindowsForms
应用程序中处理DataGridView
,我向我的DataGridView
添加了 1 列,即“名称”,并通过选择行到文本框来显示它,但它只显示一列,即“名称”到文本框。 But i have other columns like city state, that I have not added to my DataGridView
Is there any way to display all the database record by clicking on single column "Name " from DataGridView
to Textboxes
?但是我有其他列,如城市状态,我没有添加到我的
DataGridView
有没有办法通过单击从DataGridView
到Textboxes
单列“名称”来显示所有数据库记录?
private void dataGridView1_CellClick
(object sender, DataGridViewCellEventArgs
e){ i = e.RowIndex; private void
dataGridView1_CellClick
(object sender, DataGridViewCellEventArgs
e){ i = e.RowIndex; DataGridViewRow row = this.dataGridView1.Rows[e.RowIndex]; DataGridViewRow row = this.dataGridView1.Rows[e.RowIndex];
textBox1.Text = row.Cells[0].Value.ToString();
String str = "server=PC2-PC;database=demo;Integrated Security=true";
SqlConnection con = new SqlConnection(str);
con.Open();
if (e.RowIndex != -1)
{
textBox1.Text = dataGridView1.Rows[e.RowIndex].Cells[Name].Value == null ? "" : dataGridView1.Rows[e.RowIndex].Cells[Name].Value.ToString();
CallData();
}
}
with your solution, you can build other columns in DataGridView and change Visible to false.使用您的解决方案,您可以在 DataGridView 中构建其他列并将 Visible 更改为 false。 in this way you can fill them when you filling Name Column and use their's data when user click on a row and show in TextBoxes.
通过这种方式,您可以在填充名称列时填充它们,并在用户单击一行并在文本框中显示时使用它们的数据。
but this way of using database in form events, is not a standard code.但是这种在表单事件中使用数据库的方式并不是标准代码。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.