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. (Last updated on: November 16, 2018).
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

How to synchronize two grids appearance at run-time

Thread ID:





26683 Mar 30,2005 03:08 AM UTC Mar 30,2005 08:27 AM UTC WinForms 1
Tags: GridControl
Asked On March 30, 2005 03:08 AM UTC

Say I have two DataBoundGrids in a User Control. How to sync the two grids? For example, when I resize a Column1 in Grid1, I also want Column1 in Grid2 to be resized simultaneously (when dragging the Column1 in either grids). And, when there''s a scroll bar in Grid1, I want Grid2 to have a scroll bar too (scrolling should occur in both grids simultaneously). Is this possible? which events triggers this? do u have sample code for this situation? NB: both grids will have the same amount of columns with same width, they might contain different values though. thanks.

Administrator [Syncfusion]
Replied On March 30, 2005 08:27 AM UTC

Yes, this is possible. For each of the actions you want to synchronize, you will have to catch an appropriate event on each grid. In your event handlers, you would have to use code to explicitly make the particular action occur on the grid that did not generate the event. If you use teh same handler code for both grids, you would need to make sure you avoid recursive calls (like changing colwidth in first grid triggerring colwidth change in second grid triggerring colwidth change in first grid and so on. To handle the two actions you mentioned, you can handle these events. this.gridDataBoundGrid1.TopRowChanged += new GridRowColIndexChangedEventHandler(grid_TopRowChanged); this.gridDataBoundGrid2.TopRowChanged += new GridRowColIndexChangedEventHandler(grid_TopRowChanged); this.gridDataBoundGrid1.Model.ColWidthsChanged += new GridRowColSizeChangedEventHandler(Model_ColWidthsChanged); this.gridDataBoundGrid2.Model.ColWidthsChanged += new GridRowColSizeChangedEventHandler(Model_ColWidthsChanged);
private bool inTopRowChanged = false; 
private void grid_TopRowChanged(object sender, GridRowColIndexChangedEventArgs e)
		inTopRowChanged = true;
		GridDataBoundGrid master = sender as GridDataBoundGrid;
		GridDataBoundGrid slave;
		if(master == this.gridDataBoundGrid1)
			slave = this.gridDataBoundGrid2;
			slave = this.gridDataBoundGrid1;

		slave.TopRowIndex = master.TopRowIndex;
		inTopRowChanged = false;

private bool inColWidthsChanged = false;
private void Model_ColWidthsChanged(object sender, GridRowColSizeChangedEventArgs e)
		inColWidthsChanged = true;
		GridModel master = sender as GridModel;
		GridModel slave;
		if(master == this.gridDataBoundGrid1.Model)
			slave = this.gridDataBoundGrid2.Model;
			slave = this.gridDataBoundGrid1.Model;

		for(int col = e.From; col <= e.To; ++col)
			slave.ColWidths[col] = master.ColWidths[col];
		inColWidthsChanged = false;


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.

Please sign in to access our forum

This page will automatically be redirected to the sign-in page in 10 seconds.

Warning Icon 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.Close Icon