DataTable employeeCollection = new DataTable();
employeeCollection.Columns.Add("Column1", typeof(string));
employeeCollection.Columns.Add("Column2", typeof(string));
this.sfDataGrid.DataSource = employeeCollection;
this.sfDataGrid.AutoSizeColumnsMode = AutoSizeColumnsMode.AllCells;
private void button1_Click(object sender, EventArgs e)
{
employeeCollection.Rows.Add("short", "really long text is truncated");
employeeCollection.Rows.Add("short", "really long text is truncated");
employeeCollection.Rows.Add("short", "really long text is truncated");
employeeCollection.Rows.Add("short", "really long text is truncated");
this.sfDataGrid.AutoSizeController.ResetAutoSizeWidthForAllColumns();
this.sfDataGrid.AutoSizeController.Refresh();
} |
this.sfDataGrid1.View.Records.CollectionChanged += Records_CollectionChanged;
private void Records_CollectionChanged(object sender, System.Collections.Specialized.NotifyCollectionChangedEventArgs e)
{
if (this.sfDataGrid1.View.Records.Count > 0)
{
sfDataGrid1.AutoSizeController.ResetAutoSizeWidthForAllColumns();
sfDataGrid1.AutoSizeController.Refresh();
}
}
|