4

I have a DataSet that I create at runtime. I would like to display this information in a datagrid using wpf and have it display certain columns chosen at runtime.

I can get the data to display using:

datagrid.ItemsSource = dataset.Tables[0].DefaultView;
datagrid.DataContext = dataset.Tables[0];

How do I use DataGridTemplateColumn to add columns to the data grid and have my dataset's information displayed in them or other arbitrary data (numeration, etc)?

Thank you.

slugster
  • 49,403
  • 14
  • 95
  • 145
Roger
  • 41
  • 1
  • 1
  • 2

1 Answers1

3

Check if these previous StackOverflow questions answer yours:

(Here is the search I used).

Basically you need to add columns to the datagrid, and set their binding (using the Binding property). There are a variety of columns to choose from, you want one that derives from DataGridBoundColumn such as DataGridTextColumn.

Community
  • 1
  • 1
slugster
  • 49,403
  • 14
  • 95
  • 145
  • I've tried this with no luck. Setting ItemsSource to a DataView Property doesn't work for me. I can get it to work in c# by setting the ItemsSource and DataConext of the data grid. But this only works using auto create columns. As soon as I create custom columns it breaks. – Roger Jan 08 '11 at 02:30
  • @Roger - this would indicate that your bindings are incorrect. You need to edit your question and post some extra details, like what the dataset looks like and what your binding code looks like. – slugster Jan 08 '11 at 07:13