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 calculate the minimum possible height for a grid

i want to resize a grid control based upon the number of rows in it (it is part of a splitter control and i want the splitter to move when rows are added.) i can find out the size of all the rows with the RowSizes property, and this works just fine. BUT.. heres the problem It is a databound control fed with a DataTable. if i change the data source to add a row then the grid correctly displays the new data. Thats just fine... SO... what i want to do is detect that a row has been added. now the datatable gives me events to do this so i tried that. unfortunately though this RowAdded event is getting to my code BEFORE the values in RowSizes reflects the new data. so i thought - ok - i''ll call Application.DoEvents() and that''ll force the grid to update itself. unfortunately this doesnt work either. its as if the datagrid isnt drawing until much later. THEREFORE i thought i could use the Model.DataChanged, Model.ConfirmingPendingChanges or Model.RowsInserted events on the datatable to detect changes. however these events dont seem to get raised for changes made from a datatable changing SO i''m stuck right now. any bright ideas? my best thought is to start a timer when new rows are added and then do my refresh.

2 Replies

AD Administrator Syncfusion Team January 17, 2004 06:40 AM UTC

The ListChanged event on the IBindingList object associated with the CurrencyManager for your datasource fires after the row is added. ''subscribe to the event Dim cm As CurrencyManager = Me.BindingContext(Me.GridDataBoundGrid1.DataSource, Me.GridDataBoundGrid1.DataMember) Dim ibl As IBindingList = cm.List AddHandler ibl.ListChanged, AddressOf ibl_ListChanged ''the handler Private Sub ibl_ListChanged(ByVal sender As Object, ByVal e As ListChangedEventArgs) If e.ListChangedType = ListChangedType.ItemAdded Then Console.WriteLine(Me.GridDataBoundGrid1.Model.RowCount) End If End Sub


AD Administrator Syncfusion Team January 17, 2004 06:45 AM UTC

Here is some C# code.
//subscribe to the event
CurrencyManager cm = (CurrencyManager) this.BindingContext[this.gridDataBoundGrid1.DataSource, this.gridDataBoundGrid1.DataMember];
IBindingList ibl = cm.List as IBindingList;
if(ibl != null)
	ibl.ListChanged += new ListChangedEventHandler(ibl_ListChanged);

//the handler
private void ibl_ListChanged(object sender, ListChangedEventArgs e)
{
	if (e.ListChangedType == ListChangedType.ItemAdded)
		Console.WriteLine(Me.GridDataBoundGrid1.Model.RowCount);
}

Loader.
Up arrow icon