Skip to content

Instantly share code, notes, and snippets.

@erodewald
Created August 8, 2012 17:56
Show Gist options
  • Save erodewald/f5bdb54009b71466d271 to your computer and use it in GitHub Desktop.
Save erodewald/f5bdb54009b71466d271 to your computer and use it in GitHub Desktop.
A very crappy example of auto-sizing columns for ComponentOne FlexGrid.
public MainWindow()
{
InitializeComponent();
Loaded += MainWindow_Loaded;
}
void MainWindow_Loaded(object sender, RoutedEventArgs e)
{
List<string> items = new List<string>();
var b1 = "some text";
var b2 = "some text is long";
var b3 = "some text is longer ";
var b4 = "some text is much longer";
var b5 = "some text is so long you won't read this";
Binding bind1 = new Binding { Source = b1 } ;
Binding bind2 = new Binding { Source = b2 } ;
Binding bind3 = new Binding { Source = b3 } ;
Binding bind4 = new Binding { Source = b4 } ;
Binding bind5 = new Binding { Source = b5 } ;
items.Add(b1);
items.Add(b2);
items.Add(b3);
items.Add(b4);
items.Add(b5);
flexGrid.ItemsSource = items;
flexGrid.Columns.Add(new Column { Header = "short col", Width = GridLength.Auto, Binding = bind1 });
flexGrid.Columns.Add(new Column { Header = "longer col", Width = GridLength.Auto, Binding = bind2 });
flexGrid.Columns.Add(new Column { Header = "really long col", Width = GridLength.Auto, Binding = bind3 });
flexGrid.Columns.Add(new Column { Header = "super duper long col", Width = GridLength.Auto, Binding = bind4 });
flexGrid.Columns.Add(new Column { Header = "why is this col so long?", Width = GridLength.Auto, Binding = bind5 });
flexGrid.AutoSizeColumns(0, 4, 5);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment