We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date

How to call ResizeToFit after DataBoundGrid is sorted or filtered

I''m performing custom row and column on sizing my GridDataBoundGrid using ResizeToFit(). This works fine after loading data into the grid, but when a user filters (I''m using GridFilterBar) or sorts (clicks on header cells) I need to call ResizeToFit(). It''s not obvious to me what events I should use to keep my grid sized correctly. I tried FilterBarTextChanged, but it seems to be fired before all data is loaded. Thanks for the help!

2 Replies

AD Administrator Syncfusion Team September 2, 2004 12:24 PM

You can try to subscribe to the DataaView''s ListChanged event. There is the type is a Reset, then you can do your resize. Here is code that work for me in our GridFilterBar sample.
//at the bottom of SetTableIntoGridAndWireFilterBar
DataTable dt = this.gridDataBoundGrid1.DataSource as DataTable;
if(dt != null)
{
	dt.DefaultView.ListChanged += new ListChangedEventHandler(DefaultView_ListChanged);
}

//handler
private void DefaultView_ListChanged(object sender, ListChangedEventArgs e)
{
	if(e.ListChangedType == ListChangedType.Reset)
	{
		this.gridDataBoundGrid1.Model.ColWidths.ResizeToFit(GridRangeInfo.Table());
	}
}


LM Luke Middleton September 2, 2004 12:41 PM

Works great! Thank you.

Loader.
Live Chat Icon For mobile
Up arrow icon