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

Cell Formatting

Thread ID:

Created:

Updated:

Platform:

Replies:

5024 Jun 16,2003 01:05 AM UTC Jun 17,2003 10:22 PM UTC WinForms 4
loading
Tags: GridControl
Hong Chen
Asked On June 16, 2003 01:05 AM UTC

I have 2 quiestions: 1. When I use gridControl.Model.GetCombinedStyle to get a style, change the style using PropertyGrid (without applying any CellValue), and apply the style using grid.ChangeCells, in virtual grid mode, SaveCellInfo event is fired twice. The worst thing of this is that HasCellValue is true, but CellValue property is a blank string when it should not be blank. 2. If 2 adjacent cells' style.Borders.Top, Bottom, Left, Right have solid lines, then it will end up with 2 solid lines between the 2 cells. This is not the same as Excel formatting. Are there any way to correct these problems? Regards Hong

Administrator [Syncfusion]
Replied On June 16, 2003 07:11 AM UTC

1) I tried to see this behavior in the CellStyles sample, and could not. In that sample, I could only see SaveCellInfo being hit once per row/col after applying a change. I added two buttons, one to populate the property grid with a combined style, and one to apply the the style in the property grid to a particular cell. When I clicked the 2nd button, SaveCellInfo is only hit once. I suspect the behavior you are seeing is due particular to your code. Can you post a sample project showing this problem, or create a Direct Trac support incident with a sample? 2) This behavior is by design. Grid cells do not share borders with their neighboring cells. By default, the grid only applies borders to the bottom and right of each cell. This avoids the double border look that you described. If you want the cells to share borders, then you can get dynamically change the neighbor border when the current cell's border changes, and always draw just one border. I think you can do this in SaveCellInfo (change the neighbor border) and PrepareViewStyleInfo(draw only one joint border).
private void gridControl1_SaveCellInfo(object sender, GridSaveCellInfoEventArgs e)
{
	if(e.ColIndex > 1 && e.RowIndex > 1)
	{
		if(this.gridControl1[e.RowIndex, e.ColIndex-1].Borders.Right != 
				style.Borders.Left)
			this.gridControl1[e.RowIndex, e.ColIndex-1].Borders.Right = style.Borders.Left;
				
		if(this.gridControl1[e.RowIndex - 1, e.ColIndex].Borders.Bottom != 
				style.Borders.Top)
			this.gridControl1[e.RowIndex - 1, e.ColIndex].Borders.Bottom = style.Borders.Top;
 	}
}

private void gridControl1_PrepareViewStyleInfo(object sender, Grid.GridPrepareViewStyleInfoEventArgs e)
{
	if(e.ColIndex > 0 && e.RowIndex > 0)
	{
		e.Style.Borders.Left = new GridBorder(GridBorderStyle.None);
		e.Style.Borders.Top = new GridBorder(GridBorderStyle.None);
	}
}

Hong Chen
Replied On June 17, 2003 03:20 AM UTC

Regarding Answer 1: After getting combined style, if only save a few properties, duplicate firing of SaveCellInfo doesn't happen. However, if save all the GridStyleInfo, then this will happen. I don't know which property is the trouble maker. Regarding Answer 2: What if a user wants thin blue solid border around some cells but thick blue solid border around others? Then the workaround becomes too complex. Not to mention that in virtual grid we have to save borders, the workaround you suggested will actually change user's editing. I think Syncfusion should consider of merging of border in paint event. Thanks for your response.

Administrator [Syncfusion]
Replied On June 17, 2003 08:40 AM UTC

1) SaveCellInfo should only be called once for each cell list the range used in ChangeCells. I applied the StyleInfo.Default style (which have every property set) in a ChangeCells call, and SaveCellInfo was only hit once. I suspect it is something in your implementation that is causing this behavior. Can you post a sample? Or, can you place a stop in SaveCellInfo, and look at the call stacks in the two hits to see if that gives any hit as to what is going on. 2) If the user wants thin borders around some cells and thick borders around others, with these events handled as above, he would just set the style.Border properties as he does now. Using this excel like common border, one cell cannot have a thick border on the right, and its adjacent cell have a thin border because they share the border. The last border value set will be the border used. But, that is how it would also work in excel. With the grid default border behavior, there is no problem with adjacent borders being different as each cell owns all four borders. You probably would want to avoid the change events from being fired. But calling grid.SuspendChangeEvents/ResumeChangeEvents as below should handle this problem. Changing how the grid handles the borders would be a major architectural change (I think). It affects scrolling, and anything that affects scrolling is a big change as a lot of effort has gone into optimizing scrolling.
private void gridControl1_SaveCellInfo(object sender, GridSaveCellInfoEventArgs e)
{
	if(e.ColIndex > 1 && e.RowIndex > 1)
	{
		if(this.gridControl1[e.RowIndex, e.ColIndex-1].Borders.Right != 
			e.Style.Borders.Left)
		{
			this.gridControl1.SuspendChangeEvents();
			this.gridControl1[e.RowIndex, e.ColIndex-1].Borders.Right = e.Style.Borders.Left;
			this.gridControl1.ResumeChangeEvents();
		}
				
		if(this.gridControl1[e.RowIndex - 1, e.ColIndex].Borders.Bottom != 
			e.Style.Borders.Top)
		{
			this.gridControl1.SuspendChangeEvents();
			this.gridControl1[e.RowIndex - 1, e.ColIndex].Borders.Bottom = e.Style.Borders.Top;
			this.gridControl1.ResumeChangeEvents();
		}
	}
}

Hong Chen
Replied On June 17, 2003 10:22 PM UTC

Regarding Question 1: I compare the calling stack, the first call is: GridModel::ChangeCells-->GridModel::ChangeCells-->GridModel::SetCellInfo-->GridModel::SetCellInfo-->GridModelOnSaveCellInfo-->GridControl:: ModelSaveCellInfo-->GridControl::OnSaveCellInfo-->SaveCellInfo event handler The 2nd call for the very same row-col coordination is: GridControl::OnSaveCellInfo-->GridFormulaModel:: GridFormulaCellInfo, then starts to call a lot of other methods, then fire SaveCellInfo event handler. Interestingly enough, this 2nd call doesn't happen if I create a new GridStyleInfo, change the border, call ChangeCells. However, If call GetCombinedStyle, then populate the style in a propertyGrid, then change the Borders.Left, Borders.Top, Borders.Right, Borders.Bottom to Solid style, the 2nd call will occur. Anyway I have got a work around to it now. But I still feel unconfortable that this event is called twice. Regarding formula mode, I change BaseStylesMap["Standard"].StyleInfo.CellType as "FormulaCell", maintain a HashTable of formula tag for virtual grid (as you suggested). When this problem happens, no formula even exists in the grid. Regarding the 2nd question, I understand the gravity of changing the drawing method. I might use your suggestion as the start point. But I am sure this workaround don't just work. I have to cater for various combinations of adjacent cell border styles.

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.

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

;