开发者

c# DataSet To DataGrid

I would like to convert my dataset which contains one table into a datagrid in order to get the width of each column to add many groups title with the correct width just above.

I've tried " mydatagrid.ItemsSource = mydataset.Table[0].defaultview;" and it works properly except this instruction doesn't fill any columns in my datagrid so i can't get any开发者_如何学运维 width of any columns.

If anyone have an idea, thanks a lot.


Have you set AutoGenerateColumns = true?

http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.datagrid.autogeneratecolumns.aspx

Your question sounds a bit strange. You DO know, that DataGrid is a web control, yes?


First of all, there are two DataGrid controls: one in System.Windows.Forms namespace for Windows Forms and the other in System.Web.UI.WebControls for Web.

In either case, DataGrid is a control that shows a data from a data source in a grid. In order to show the data, you have to bind it to a control.

This is quote from DataGrid article: "To display a table in the System.Windows.Forms.DataGrid at run time, use the SetDataBinding method to set the DataSource and DataMember properties to a valid data source."

dataGrid1.SetDataBinding(SuppliersProducts, "Suppliers");


So i'm back with a solution. My columns were empty cause my code was define before the event "Loaded" happen so now everything is perfect.

Thanks for precision about the datagrid.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜