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.

Backcolor

Thread ID:

Created:

Updated:

Platform:

Replies:

18190 Aug 25,2004 12:20 PM Feb 16,2005 12:56 PM Windows Forms 9
loading
Tags: GridControl
Jim Frapper
Asked On August 25, 2004 12:20 PM

Hey, I would like to change the background color for one row in my databound grid. I am a little confused as to why the first statement below does not work but the second one does. this.gridWeek1Session1.Model.RowStyles[2].BackColor = System.Drawing.Color.LightCyan; this.gridWeek1Session1.Model.ColStyles[2].BackColor = System.Drawing.Color.LightCyan; For my purposes of changing the backcolor, using the PrepareViewStyleInfo is too much work because I am using multiple grids on my interface. I really would like a one liner to change the row backcolor. My version of the grid is an older version so it could be something that was fixed in the current versions. Mine is 1.6.1.8. Cheers, JF

Administrator [Syncfusion]
Replied On August 25, 2004 12:23 PM

ColStyles[] are used in GridControl. For a GridDataBoundGrid, you use GridBoundColumns. Here is a KB link. http://www.syncfusion.com/Support/article.aspx?id=562

Jim Frapper
Replied On August 25, 2004 12:38 PM

Hey Clay, Thanks for getting back to me so fast. If you take a look at my previous post, you will notice that I didn''t have any problems with setting the column styles. My difficulty was setting the row styles. JF

Jim Frapper
Replied On August 25, 2004 01:20 PM

Hey Clay, I seem to have found my answer. http://www.syncfusion.com/Support/article.aspx?id=561 You cant do it with a one liner. Dam Cheers, JF

Bill
Replied On February 15, 2005 08:35 PM

Hey guys, In a data bound grid, can you change the backcolor of a cell that is double-clicked? I can''t seem to get this to work. Thanks, Bill >Hey Clay, > >I seem to have found my answer. > >http://www.syncfusion.com/Support/article.aspx?id=561 > >You cant do it with a one liner. Dam > >Cheers, >JF

Administrator [Syncfusion]
Replied On February 15, 2005 09:05 PM

You would need to do this through PrepareViewStyleInfo. Try setting this property: this.gridDataBoundGrid1.ActivateCurrentCellBehavior = GridCellActivateAction.None; and handling these events.
ArrayList doubleClickedCells = new ArrayList();
private void gridDataBoundGrid1_DoubleClick(object sender, EventArgs e)
{
	int row, col;
	Point pt = this.gridDataBoundGrid1.PointToClient(Cursor.Position);
	if(this.gridDataBoundGrid1.PointToRowCol(pt, out row, out col))
	{
		int code = GetLookUpCode(row, col);
		if(doubleClickedCells.IndexOf(code) == -1)
			doubleClickedCells.Add(code);
			else
			doubleClickedCells.Remove(code);
		this.gridDataBoundGrid1.RefreshRange(GridRangeInfo.Cell(row, col), true);
	}
}
private void gridDataBoundGrid1_PrepareViewStyleInfo(object sender, GridPrepareViewStyleInfoEventArgs e)
{
	if(doubleClickedCells.IndexOf(GetLookUpCode(e.RowIndex, e.ColIndex)) > -1)
	{
		e.Style.BackColor = Color.Blue;
	}
}


Bill
Replied On February 16, 2005 10:48 AM

Clay, Thanks for the quick response. I have tried yoru sample. What does GridCellActiviateAction do or not do? and what library is GetLookUpCode? I teach programming classes. At the end of the sessions, I let the students try and stump me. Someone asked this. As I tried, I was bragging how easy controls make coding. I guess I should have researched a bit more. Thanks Again, Bill >You would need to do this through PrepareViewStyleInfo. > >Try setting this property: > >this.gridDataBoundGrid1.ActivateCurrentCellBehavior = GridCellActivateAction.None; > > >and handling these events. >
>ArrayList doubleClickedCells = new ArrayList();
>private void gridDataBoundGrid1_DoubleClick(object sender, EventArgs e)
>{
>	int row, col;
>	Point pt = this.gridDataBoundGrid1.PointToClient(Cursor.Position);
>	if(this.gridDataBoundGrid1.PointToRowCol(pt, out row, out col))
>	{
>		int code = GetLookUpCode(row, col);
>		if(doubleClickedCells.IndexOf(code) == -1)
>			doubleClickedCells.Add(code);
>			else
>			doubleClickedCells.Remove(code);
>		this.gridDataBoundGrid1.RefreshRange(GridRangeInfo.Cell(row, col), true);
>	}
>}
>private void gridDataBoundGrid1_PrepareViewStyleInfo(object sender, GridPrepareViewStyleInfoEventArgs e)
>{
>	if(doubleClickedCells.IndexOf(GetLookUpCode(e.RowIndex, e.ColIndex)) > -1)
>	{
>		e.Style.BackColor = Color.Blue;
>	}
>}
>
>

Administrator [Syncfusion]
Replied On February 16, 2005 11:01 AM

The ActivateCurrentCellBehavior controls what happens when a cell becomes current. Setting it to none means that double-clicking the cell will not activate the cell control for editing. If you have it set to something else, then clicking the cell will activate it, and the seoncd click in the double click goes to the cell control. In this case, grid.DoubleClick is not raised (instead grid.CurrentCellControlDoubleClick is raised). So, setting this property to none just makes sure grid.DoubleClick is hit. The GetLookUpCode method was just something to generate a unique code for a row and column. I should have listed a sample such as this: private int GetLookUpCode(int row, int col) { return 10000 * col + row; }

Bill
Replied On February 16, 2005 12:52 PM

Clay, Thanks a bunch. I had to change a line , maybe a version issue? Regardless, I would have never thought to capture the doule click in the grid itself: this.gridDataBoundGrid1.RefreshRange(gridDataBoundGrid1.GridCellsRange, true); Bill >The ActivateCurrentCellBehavior controls what happens when a cell becomes current. Setting it to none means that double-clicking the cell will not activate the cell control for editing. If you have it set to something else, then clicking the cell will activate it, and the seoncd click in the double click goes to the cell control. In this case, grid.DoubleClick is not raised (instead grid.CurrentCellControlDoubleClick is raised). So, setting this property to none just makes sure grid.DoubleClick is hit. > >The GetLookUpCode method was just something to generate a unique code for a row and column. I should have listed a sample such as this: > >private int GetLookUpCode(int row, int col) >{ > return 10000 * col + row; >} >

Bill
Replied On February 16, 2005 12:56 PM

Sorry, to bother you again. This answers the question, but we lose the ability to edit the field. Is there a method I can call to allow this to happen inside the gridDataBoundGrid1_PrepareViewStyleInfo? Bill

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.

;