0
votes

I want to bind a data grid view. After binding, I need to hide a column from the datagrid. My code is:

datagrid.DataContext = Dttable  

For each gdColumn as DataGridColumn in datagrid.Columns

    If gdColumn.Header = "ID" Then
        gdColumn.Visiblity = False
    end if

Next

But here datagrid.Columns is 0 even though I have 3 columns.

Please help me to do this

1
Post your xaml for the DataGrid, based on your current code you are only setting the DataContext and not the ItemsSource. - Xtr

1 Answers

0
votes

You seem to be doing hiding right after you bind the data. Handle the datagrid.Loaded event and do the rest of your code there.

WPF control's Loaded event is triggered after DataBinding is complete.