我正在使用C#WinForms。我想在网格中显示数据。网格必须能够响应行上的点击。什么是最好的组件使用?C#:在网格中显示数据的最佳方式?
2
A
回答
4
他很长时间在谈论类似于按钮点击的事件。 DataGridView应该能够包含像下拉菜单这样的控件,因此您将能够添加一个依赖于所选单元格的响应。
尝试
private void GetData(string selectCommand)
{
// Specify a connection string. Replace the given value with a
// valid connection string for a Northwind SQL Server sample
// database accessible to your system.
String connectionString =
"Integrated Security=SSPI;Persist Security Info=False;" +
"Initial Catalog=Northwind;Data Source=localhost";
// Create a new data adapter based on the specified query.
dataAdapter = new SqlDataAdapter(selectCommand, connectionString);
// Create a command builder to generate SQL update, insert, and
// delete commands based on selectCommand. These are used to
// update the database.
SqlCommandBuilder commandBuilder = new SqlCommandBuilder(dataAdapter);
// Populate a new data table and bind it to the BindingSource.
DataTable table = new DataTable();
table.Locale = System.Globalization.CultureInfo.InvariantCulture;
dataAdapter.Fill(table);
bindingSource1.DataSource = table;
// Resize the DataGridView columns to fit the newly loaded content.
dataGridView1.AutoResizeColumns(
DataGridViewAutoSizeColumnsMode.AllCellsExceptHeader);
}
private void Form1_Load(object sender, System.EventArgs e)
{
// Bind the DataGridView to the BindingSource
// and load the data from the database.
dataGridView1.DataSource = bindingSource1;
GetData("select * from Customers");
}
0
DataGridView。
但我不明白你的意思是“他的网格必须能够响应点击行”。
编辑:您可以使用datagridview中的各种事件来跟踪哪个行,哪个列以及您单击了哪个单元格。此外,Gridview支持列中的按钮,链接按钮和图像等控件。
+0
我将有另一个数据网格,显示其他数据取决于第一个网格点击哪一行。 – 2011-03-01 09:13:12
+0
@克莱格约翰斯顿:我修改了答案。 – Anuraj 2011-03-01 09:17:00
0
必须无法在数据网格的整个行选择属性,然后在行单击或双击(任何你想要的)事件中添加代码。
0
在DataGrid中你有一个事件。如果你在下面做这样的事情,你可以管理CLick。
public Form1()
{
InitializeComponent();
dataGridView1.RowStateChanged += new DataGridViewRowStateChangedEventHandler(dataGridView1_RowStateChanged);
}
void dataGridView1_RowStateChanged(object sender, DataGridViewRowStateChangedEventArgs e)
{
DataGridViewRow dgvr = e.Row;
//GetDataFrom Database to fill other Grid
}
相关问题
- 1. 在winforms中以网格格式显示多列数据的最佳方法?
- 2. 在网格状结构中显示动态数据的最佳方式
- 3. 什么是在网格中显示“焦点”的最佳方式?
- 4. 以行和列的格式显示数据的最佳方式
- 5. 在zend中显示html表格数据的最佳方法
- 6. 在网页中显示网页的最佳方式?
- 7. 在表格填写数据后显示数据的最佳方式
- 8. 表示单元格在网格中呈现的格式的最佳方式?
- 9. 在ASP.Net中显示/格式SQL 2005钱数据类型的最佳方法
- 10. 编辑wpf数据网格中整行的最佳方式?
- 11. 在Visual Studio中显示jpeg流的最佳方式C++
- 12. 修改datetime在数据网格中的显示方式?
- 13. Android:显示表格数据的最佳方法
- 14. 显示格式文本的整个章节的最佳方式
- 15. 在网页上显示通知和消息的最佳方式?
- 16. 在网页上显示Ruby代码的最佳方式?
- 17. 显示/格式表格数据(网络)
- 18. C#读取XLS(XLSX)文件并填充数据网格的最佳方式
- 19. 显示数据录入错误的最佳方式
- 20. 使用jQuery通过JSON显示数据的最佳方式
- 21. 显示关联数据的最佳方式是什么?
- 22. Watchkit:显示大量数据的最佳方式
- 23. 在Erlang中表示C数组的最佳方式是什么?
- 24. 在C#中表示参数化枚举的最佳方式?
- 25. 显示SQL结果的最佳方式
- 26. 显示12列表的最佳方式
- 27. 的最佳方式[,]数组在C#
- 28. 在集合中表示类似数据的表格的最佳方式
- 29. 在WordPress中格式化C#的最佳方式是什么?
- 30. 在MVC框架的主布局中显示模型数据的最佳方式
在.NET中内置的DataGrid会为你工作得很好。 您是否想要关于如何将数据绑定到DataGrid的示例代码? – 2011-03-01 09:10:20
有请示例代码。 – 2011-03-01 09:13:53
这不是在这篇博客文章讨论的内容的范围内吗? http://blog.stackoverflow.com/2011/02/are-some-questions-too-simple/ – Mayank 2011-03-01 09:21:24