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.
Unfortunately, activation email could not send to your email. Please try again.

How to calculate the minimum possible height for a grid

Thread ID:

Created:

Updated:

Platform:

Replies:

9945 Jan 16,2004 06:57 PM Jan 17,2004 01:45 AM Windows Forms 2
loading
Tags: GridControl
simon
Asked On January 16, 2004 06:57 PM

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.

Administrator [Syncfusion]
Replied On January 17, 2004 01:40 AM

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

Administrator [Syncfusion]
Replied On January 17, 2004 01:45 AM

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);
}

CONFIRMATION

This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.

;