views:

56

answers:

3

Hi,

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.

A: 

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?

Hinek
He seems to be using the WinForms control, not the ASP.NET one?
slugster
Ok so,i'm using WPF,and my datagrid is for a .Net Application not a WebSite.I've already succeed to set my datagrid to my dataset,everything works fine,but when i'm debugging I can see,there are no columns in the column's collection of my datagrid so I can't iterate in order to get the width of each columns.
Doncho
Ok so it's win, not web. But my point was: it is a control, it is used to display data, not (at least not primary) to measure column width. That said: Does your grid display data? Have you tried AutoGenerateColumns?
Hinek
When i'm doing " mydatagrid.ItemsSource = mydataset.Table[0].defaultview;"my datagrid display datas and columns,and i can order and do what you can do with a datagrid.My main problem is i would like to display a custom crosstable,so I would like to create custom label just above my datagrid to give impression of a crosstab that's why I need to know the width of each column to calcul the width of a group of columns in order to create a label with the correct width to give the impression of a crosstab.
Doncho
Actually,i'm trying to fill my datagrid from my dataset.First, I have define every column which works fine,but I didn't know how to add items.I've tried to use ItemsSource of my datagrid but it gives me the correct number of rows but i didn't know how to set every cell for each columns.
Doncho
Sorry, can't help ... if the data is displayed correctly, DataGrid.Columns should contain the columns ... good luck anyway.
Hinek
A: 

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");
Nenad
Ok thanks for the precision,but I forget to mention,i'm working with WPF,and my DataGrid which is use in my xaml, use the namespace "Microsoft.Windows.Controls" and I don't know how to use other datagrid in xaml.
Doncho
A: 

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.

Doncho