Home > Silverlight > Showing and Hiding Datagrid Columns

Showing and Hiding Datagrid Columns

if we want to show and hide DataGrid columns in Silverlight Beta2, we will run into issues if we use Visibility.Collapsed and Visibility.Visible
the following seems to work
we have to set MinColumnWidth property to 0

//grid1 name of the grid
grid1.MinColumnWidth = 0;

//hide the column
grid1.Columns[0].Width = new DataGridLength(0);

//show the column
grid1.Columns[0].Width = DataGridLength.Auto;

you can download source here

Categories: Silverlight
  1. Valerie
    June 10, 2008 at 5:38 pm | #1

    Hello, Lee! I am having problems with this topic as well. My Beta 1 code set the column’s visibility to collapsed or visible, depending on what I was doing, and worked great.

    Now that I upgraded to Beta 2, the code still works, except the column headers are not being included in the collapsing/showing. So when column1 is collapsed and column2 is shown, column1’s header stays visible and column2′ s header stays hidden.

    I tried implementing it the way you suggested, but I still have the same issue with the column headers.

  2. lee
    June 10, 2008 at 5:48 pm | #2

    I added a sample. In the sample you can see that you can hide and show first column
    let me know if that doesnt work

  1. No trackbacks yet.