我想用我们可以假设已经包含数据的DataView填充我的DataGridView。我一直在寻找一种方法来做到这一点,但所有解决方案都涉及其他数据结构,而不是DataView,或涉及使用其他库,我无法在此项目中进行整合。我是否需要首先将DataView转换为其他东西并使用它来填充DataGridView?或者,除了以类似方式显示信息的DataGridView以外,还有其他可用的东西吗?用DataView填充DataGridView
1
A
回答
1
尝试将的DataSource
财产设置为您的DataView
。 A DataSource
可以实现IBindingListView
或IList
接口(以及与这种情况相关的其他选项),这两个接口都由DataView
执行。
欲了解更多信息,请检查MSDN:
1
How to: Bind a DataView Object to a Windows Forms DataGridView Control
这是所有原生的,我只是用Google搜索“datagridview.datasource到数据视图”也许我错读,这不能解决您的问题,但评论,如果这样,我将尽力帮助
private void GetData()
{
try
{
// Initialize the DataSet.
dataSet = new DataSet();
dataSet.Locale = CultureInfo.InvariantCulture;
// Create the connection string for the AdventureWorks sample database.
string connectionString = "Data Source=localhost;Initial Catalog=AdventureWorks;"
+ "Integrated Security=true;";
// Create the command strings for querying the Contact table.
string contactSelectCommand = "SELECT ContactID, Title, FirstName, LastName, EmailAddress, Phone FROM Person.Contact";
// Create the contacts data adapter.
contactsDataAdapter = new SqlDataAdapter(
contactSelectCommand,
connectionString);
// Create a command builder to generate SQL update, insert, and
// delete commands based on the contacts select command. These are used to
// update the database.
SqlCommandBuilder contactsCommandBuilder = new SqlCommandBuilder(contactsDataAdapter);
// Fill the data set with the contact information.
contactsDataAdapter.Fill(dataSet, "Contact");
}
catch (SqlException ex)
{
MessageBox.Show(ex.Message);
}
}
相关问题
- 1. 使用DataView与MySQL填充DataGridView
- 2. 用Nhibernate填充DataGridView
- 3. 未填充datagridview
- 4. DataGridView填充
- 5. DataGridView不填充
- 6. 填充DataGridView
- 7. 填充datagridview
- 8. 用IEnumerable填充一些DataView列
- 9. 使用FileVersionInfo填充datagridview
- 10. 使用lambda填充DataGridView
- 11. datagridview Form2填充ButtonClick
- 12. C#JSON.net填充DataGridView
- 13. DataGridView Winforms填充ComboBoxCell
- 14. 填充一个DataGridView
- 15. c#很慢填充datagridview
- 16. 从线程填充DataGridView
- 17. 填充DataGridView的问题
- 18. 从JSON数组填充DataGridView
- 19. 从DB VB.NET填充Datagridview
- 20. 使用对象列表填充datagridview
- 21. C#:用DataTable填充DataGridView创建空表
- 22. 填充DataGridView使用SQL查询
- 23. 通知用户DataGridView正在填充
- 24. 用DataGridView信息填充文本框
- 25. 使用DataView更新DataGridView数据
- 26. 从DataGridView提取数据并填充XML
- 27. C#OleDb dataGridView填充文本框
- 28. 填充的dataGridView感谢对BackgroundWorker的
- 29. 从匿名Linq查询填充WinForms DataGridView
- 30. 保存datagridview动态填充C#
显然,我可以只使用数据视图表属性,并以此作为DataGridView的DataSource。我会尝试一下,并将其作为解决方案,如果它的工作。 – Boumbles