views:

1487

answers:

1

I want to define the "Auto" width of a GridView Column in the code. How can i do that?

var grid = (GridView)myListview.View;
grid.Columns.Add(new GridViewColumn
{
   Header = "My Header",
   DisplayMemberBinding = new Binding("MyBinding"),
   Width = ??? // Auto
});
+3  A: 

GridViewColumn's Width property is of type double, but according to the MSDN page you can set it to Double.NaN ("not a number") to tell it to auto-size.

If you do that, you have to ask for its ActualWidth if you want to know the width it has auto-sized to.

Matt Hamilton