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


3 thoughts on “Showing and Hiding Datagrid Columns

  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. 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

  3. This works like a charm.. after searching countless posts about this I am glad I stumbled upon this one.. worked well with telerik radgridview..

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s