views:

83

answers:

3

So i Got a tmplist of ObservableCollection in which i got few elements.

I connect it to the ItemsSource of DataGrid in WPF 4.0 and it doesn't show anything. Doesn't add any colums. If I add breakpoint I can see that the "ItemsSource count equals quantity of tmplist elements, but the Columns count equals 0. Why is that? Here is some code:

private ObservableCollection<Products> tmplist = new ObservableCollection<Products>(); 
public Products_view()
    {
        InitializeComponent();
        this.Loaded += new RoutedEventHandler(Products_view_Loaded);
    }

void Produkty_widok_Loaded(object sender, RoutedEventArgs e)
    {
        grid.ItemsSource = tmplist;

    }

and xaml:

  <DataGrid Name="grid" CurrentCellChanged="grid_CurrentCellChanged" CellEditEnding="grid_CellEditEnding" RowEditEnding="grid_RowEditEnding" AlternatingRowBackground="#FFA0D1EA" AlternationCount="1" Background="#FF64A0BE" RowBackground="White" />
+1  A: 

tmplist must be filled with items. Try adding an item to it in constructor for testing purposes.

hkon
But tmplist is filled. I didn't show it in code, but tmplist is filled with elements from database.
Mark
for kicks try making tmplist a public property instead
hkon
created an example, in which i do as in your example. And it works just fine....??Do you do anything fancy in one of your event handlers?
hkon
hkon, Could you plese upload a project with that example?
Mark
A: 

Check that the AutoGenerateColumns property of your datagrid is set to true.

Wallstreet Programmer
It is set to true
Mark
A: 

I wanna thank wallstreet programmer for suggesting the solution. It solved my problem. Thank you so much!

Priyanka