开发者

Why DataGrid in WPF 4.0 doesn't show Data?

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" />


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


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

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜