简体   繁体   English

c# windows 窗体应用程序中的datagridview

[英]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有没有办法通过单击从DataGridViewTextboxes单列“名称”来显示所有数据库记录?

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.

相关问题 如何清除C# windows forms中的DataGridView? - How to clear DataGridView in C# windows forms? DataGridView到Windows Forms C#上的文本文件 - DataGridView to text file on Windows Forms C# 如何使用 C# 在 datagridview Windows 窗体应用程序内的 ComboBox 中设置默认第一个值 - How to Set Default First Value in ComboBox inside the datagridview Windows Forms Application using C# 在C#中从Windows Forms应用程序中的存储过程在DataGridView中显示数据 - Show data in DataGridView from stored procedure in Windows Forms application in C# Windows窗体应用程序如何从数据层C#访问UI层中的datagridview - How to access datagridview in UI layer from data layer C# ?windows forms application C#Windows Forms DataGrid-删除网格标题/标题(不是DataGridView) - C# Windows Forms DataGrid - Remove Grid Title/Caption (Not DataGridView) 在DataGridView Windows Forms C#中合并标题和单元格 - Merge Header and Cells in DataGridView Windows Forms C# C#Windows Forms ping.Send与DataGridView的Async问题 - C# Windows Forms ping.SendAsync issues with DataGridView DataGridView 中的自定义 C# Windows 窗体 NumericUpDown 不起作用 - Custom C# Windows Forms NumericUpDown in DataGridView Not Working 如何在C#中以明智的方式在Windows中读取datagridview数据 - how to read datagridview data in windows forms coulmn wise in c#
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM