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
close icon

One place for all formating

Hi, What is the best way and where ( I mean which event) to change row height, column width, cell back color …..? I want to know where should i do all sort of formaing like cell style, column width, row hieght and setting cell cover property dynamically. I am using a GridControl. Thanks

15 Replies

AD Administrator Syncfusion Team June 2, 2004 03:10 PM UTC

There are different events for the different properties you mentioned. cell styles - PrepareViewStyleInfo row heights - QueryRowHeight col widths - QueryColWidth covered cells - QueryCoveredCells You can use these events to dynamically set values. Now if the behavior you need is more derterministic (meaning you change some value and store it in the grid, and then based on this value, you set a row height or set a column width), then there are other events (maybe CurrentCellConfirmChanges) where you could one time make the change. But if you want to do things dynamically (or are using the GridControl in virtual mode) then you would need to catch the other events listed above.


VI Vivek June 2, 2004 05:12 PM UTC

Thanks for yur reply. I need to do this dynmic formatting based on some user action/input. user action are out of Grid control. let say user checked/Unchecked some checkboxes and based on these selection, basically as soon as user check/Unchecked check box I i need to do grid formatting(hide/show row columns, style, covered cells). Do i have to some how trigger the grid''s event on the click event of check box? OR how would i force a grid to fire all the event suggested by you on click event of a check box? please do reply! thanks


AD Administrator Syncfusion Team June 2, 2004 06:02 PM UTC

Normally, to trigger these dynamic events, you force the grid to redraw all or part of itself by calling either grid.Refresh or grid.RefreshRange. This normally makes teh grid redraw and reflect the new values.


AD Administrator Syncfusion Team June 3, 2004 07:00 PM UTC

Hi, Could you please provide the little code sample to use QueryCoveredCells to cover multiple cell at multiple location? Or How would I achieve the following in QueryCoveredCells event ? programGrid.Model.CoveredRanges.Add(GridRangeInfo.Cells(11,0,12,0)); programGrid.Model.CoveredRanges.Add(GridRangeInfo.Cells(13,0,14,0)); programGrid.Model.CoveredRanges.Add(GridRangeInfo.Cells(15,0,16,0)); programGrid.Model.CoveredRanges.Add(GridRangeInfo.Cells(17,0,18,0)); GridStyleInfo rowStyle = new GridStyleInfo(); rowStyle.CellType = "Static"; rowStyle.BackColor = Color.BurlyWood; rowStyle.HorizontalAlignment = GridHorizontalAlignment.Center; rowStyle.VerticalAlignment = GridVerticalAlignment.Middle; rowStyle.Font.Size = 7; rowStyle.Font.Bold = true; programGrid.ChangeCells(GridRangeInfo.Cells(11, 0, 18, 0), rowStyle);


AD Administrator Syncfusion Team June 3, 2004 07:23 PM UTC

Here is a sample. forum_sample_5999.zip Normally, if you only have a few coveredcells, you just explicitly add them to the grid.Coveredranges collection. QueryCoveredRanges is normally used for repeating patterns of multiple covered cells (as shown in the sample code) but can be used to set explicit covered cells as well.


AD Administrator Syncfusion Team June 4, 2004 05:38 PM UTC

Hi I have the following code written in the QueryCoveredRange event. if(e.RowIndex == 0 && e.ColIndex > 0) { if(e.ColIndex % 2 == 1) { e.Range = GridRangeInfo.Cells0 ,e.ColIndex,0,e.ColIndex+1); this.programGrid[0,1].Text ="Total"; this.programGrid[0,3].Text ="03/01/2004"; this.programGrid[0,5].Text ="03/02/2004"; this.programGrid[0,7].Text ="03/03/2004"; } } When i ran it it gave me following error. "An unhandled exception of type ''System.StackOverflowException'' occurred in syncfusion.grid.dll" Help Vivek


VI viveks June 4, 2004 06:59 PM UTC

>Hi > >I have the following code written in the >QueryCoveredRange event. > >if(e.RowIndex == 0 && e.ColIndex > 0) >{ >if(e.ColIndex % 2 == 1) >{ >e.Range = GridRangeInfo.Cells0 ,e.ColIndex,0,e.ColIndex+1); >this.programGrid[0,1].Text ="Total"; >this.programGrid[0,3].Text ="03/01/2004"; >this.programGrid[0,5].Text ="03/02/2004"; >this.programGrid[0,7].Text ="03/03/2004"; > } > >} > >When i ran it it gave me following error. > >"An unhandled exception of type ''System.StackOverflowException'' occurred in syncfusion.grid.dll" > >Help >Vivek Hi clay Just the continuation of last entry If i remove the following lines from my code this.programGrid[0,1].Text ="Total"; this.programGrid[0,3].Text ="03/01/2004"; this.programGrid[0,5].Text ="03/02/2004"; this.programGrid[0,7].Text ="03/03/2004"; It works fine I have to set thesed value in the grid Please suggest if i can do this in the QueryCoveredRange event or i have to do it somewhere else. Thanks Vivek


AD Administrator Syncfusion Team June 4, 2004 08:13 PM UTC

If this is a GridControl and the values are fixed, and do not change as your program executes, then set them in FormLoad. You normally use these events to manage data that is dynamic. But if you are using fixed data in a GridControl, you can just set it once and be done with it. If you are using a GridDataBoundGrid, then you would want to set e.Style.Text to be some value (like "03/03/2004") based on what e.ColIndex and e.RowIndex are (e.ColIndex == 1 && e.RowIndex == 0).


AD Administrator Syncfusion Team June 4, 2004 09:17 PM UTC

In my previous post, I forgot to say where the last code snippet could be used. That comment is in reference to code that you can use in the PrepareViewStyleInfo event. >>If you are using a GridDataBoundGrid, then you would want to set e.Style.Text to be some value (like "03/03/2004") based on what e.ColIndex and e.RowIndex are (e.ColIndex == 1 && e.RowIndex == 0).


AD Administrator Syncfusion Team June 4, 2004 10:59 PM UTC

Thanks clay, I am using GridControl control and values are not fixed. i have to change then some time. where should i set these values? please help. thanks


AD Administrator Syncfusion Team June 5, 2004 03:44 AM UTC

You have two options, setting them in some event or setting them with the indexer when they change. To set them in an event, you can use PrepareViewStyleInfo just as in a GridDataBoundGrid.
private void gridControl1_PrepareViewStyleInfo(object sender, GridPrepareViewStyleInfoEventArgs e)
{
	if(e.RowIndex == 0 && e.ColIndex > 0)
	{
		switch(e.ColIndex)
		{
			case 1:
				e.Style.Text = "03/01/2004";
				break;
			case 2:
				e.Style.Text = "04/01/2004";
				break;
			case 3:
				e.Style.Text = "05/01/2004";
				break;
			default:
				break;
		}
	}
}
Or, if you know when the values change (ie, if you explicitly change them in code or if some event is fired when they change), then you just set them using the indexer in code at that point just like you would in FormLoad to set them initially.


VI viveks June 7, 2004 01:19 PM UTC

Clay if you could you please reply to the question i posted on friday 06/04/2004 (Reg. QueryCoveredRange event) I would realy appreciate that. I am kind of stuck with the problem. Thanks > > >>Hi >> >>I have the following code written in the >>QueryCoveredRange event. >> >>if(e.RowIndex == 0 && e.ColIndex > 0) >>{ >>if(e.ColIndex % 2 == 1) >>{ >>e.Range = GridRangeInfo.Cells0 ,e.ColIndex,0,e.ColIndex+1); >>this.programGrid[0,1].Text ="Total"; >>this.programGrid[0,3].Text ="03/01/2004"; >>this.programGrid[0,5].Text ="03/02/2004"; >>this.programGrid[0,7].Text ="03/03/2004"; >> } >> >>} >> >>When i ran it it gave me following error. >> >>"An unhandled exception of type ''System.StackOverflowException'' occurred in syncfusion.grid.dll" >> >>Help >>Vivek > > >Hi clay > >Just the continuation of last entry >If i remove the following lines from my code > >this.programGrid[0,1].Text ="Total"; >this.programGrid[0,3].Text ="03/01/2004"; >this.programGrid[0,5].Text ="03/02/2004"; >this.programGrid[0,7].Text ="03/03/2004"; > >It works fine >I have to set thesed value in the grid >Please suggest if i can do this in the QueryCoveredRange event or i have to do it somewhere else. > >Thanks >Vivek >


AD Administrator Syncfusion Team June 7, 2004 01:36 PM UTC

I am sorry, I thought I had responded. >>Please suggest if i can do this in the QueryCoveredRange event or i have to do it somewhere else. You have to do it some other place. The response immediately following the original post was trying to tell you where you need to do it. Here is what I posted there. <>If you are using a GridDataBoundGrid, then you would want to set e.Style.Text to be some value (like "03/03/2004") based on what e.ColIndex and e.RowIndex are (e.ColIndex == 1 && e.RowIndex == 0). >>


VI viveks June 8, 2004 06:57 PM UTC

Clay Can we change the background color of a cell in CellDrawn event of the Grid. I have tried the following e.Style.BackColor = Color.Red; and its not working. Can you please suggest. Thanks >I am sorry, I thought I had responded. > >>>Please suggest if i can do this in the QueryCoveredRange event or i have to do it somewhere else. > >You have to do it some other place. > > > >The response immediately following the original post was trying to tell you where you need to do it. Here is what I posted there. > >< >You normally use these events to manage data that is dynamic. But if you are using fixed data in a GridControl, you can just set it once and be done with it. > >If you are using a GridDataBoundGrid, then you would want to set e.Style.Text to be some value (like "03/03/2004") based on what e.ColIndex and e.RowIndex are (e.ColIndex == 1 && e.RowIndex == 0). > > > > > By Clay Burch at 6/4/2004 5:17:12 PM > > >In my previous post, I forgot to say where the last code snippet could be used. That comment is in reference to code that you can use in the PrepareViewStyleInfo event. > >>>If you are using a GridDataBoundGrid, then you would want to set e.Style.Text to be some value (like "03/03/2004") based on what e.ColIndex and e.RowIndex are (e.ColIndex == 1 && e.RowIndex == 0). > > >>


AD Administrator Syncfusion Team June 8, 2004 07:32 PM UTC

The cell is already drawn in the CellDrawn event so setting e.Style.BackColor there will have no effect on what the grid will draw. To set the backcolor dynamically, you should do it in PrepareViewStyleInfo which is hit before the grid tries to draw the cell.

Loader.
Live Chat Icon For mobile
Up arrow icon