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 synchronize two grids appearance at run-time

Thread ID:

Created:

Updated:

Platform:

Replies:

26683 Mar 29,2005 10:08 PM Mar 30,2005 03:27 AM Windows Forms 1
loading
Tags: GridControl
Jason
Asked On March 29, 2005 10:08 PM

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 03:27 AM

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)
{
	if(!inTopRowChanged)
	{
		inTopRowChanged = true;
		GridDataBoundGrid master = sender as GridDataBoundGrid;
		GridDataBoundGrid slave;
		if(master == this.gridDataBoundGrid1)
			slave = this.gridDataBoundGrid2;
		else
			slave = this.gridDataBoundGrid1;

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

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

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

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.

;