简体   繁体   English

如何在C#中填充简单的datagridview?

[英]How to fill simple datagridview in C#?

I am using Visual Studio 2005 I have a simple problem in which I am not able to populate my datagridview with Datatable 我正在使用Visual Studio 2005,但有一个简单的问题,即我无法用Datatable填充datagridview

Till now my code is as follows 到现在为止我的代码如下

       this.dataGridView1.DataSource = ds1.Tables[0];
        dataGridView1.AutoGenerateColumns =true;

Can anyone help 谁能帮忙

You can pass by BindingSource 您可以通过BindingSource

 // Set up the data source.
 var bindingSource1.DataSource = ds1.Tables[0];
 dataGridView1.DataSource = bindingSource1;

try to do 试着做

dataGridView1.DataSource = ds1;
dataGridView1.DataMember = "your_table_name";

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM