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

Color selected line

I want to color the selected line of a GridDataboundGrid in a particular color. I try private void gdg_CellClick(object sender, Syncfusion.Windows.Forms.Grid.GridCellClickEventArgs e) { gdg.Model.RowStyles[e.RowIndex].BackColor = System.Drawing.Color.Red; gdg.Model.Refresh(); gdg.Refresh(); } Thanks

6 Replies

AD Administrator Syncfusion Team January 18, 2005 07:07 AM UTC

You cannot ''set'' the backcolor of a row in a GridDataBoundGrid. Instead, you need to use an event to manage this. http://64.78.18.34/Support/article.aspx?id=561 If you always want to have the current row selected, you can set grid.ListBoxSelectionMode = SelectionMode.One. Then the selection color will be applied to the current row (as an overdrawn alphablended rectangle). You can control this alphablend color by setting grid.AlphaBlendSelectionColor.


SV sve January 18, 2005 07:41 AM UTC

Ok grid.ListBoxSelectionMode = SelectionMode.One works fine. However when my rowindex change programiticaly (with a currencyManager attach to a DataTable who''s populate my grid) the row isn''t underline. Is there a special refresh to do ?


SV sve January 18, 2005 07:59 AM UTC

Ok, i use and event and it works fine. Thanks. >Ok grid.ListBoxSelectionMode = SelectionMode.One works fine. However when my rowindex change programiticaly (with a currencyManager attach to a DataTable who''s populate my grid) the row isn''t underline. >Is there a special refresh to do ?


AD Administrator Syncfusion Team January 18, 2005 08:10 AM UTC

You can handle the currencymanager positionchanged event. CurrencyManager cm = (CurrencyManager) this.gridDataBoundGrid1.BindingContext[this.gridDataBoundGrid1.DataSource, this.gridDataBoundGrid1.DataMember]; cm.PositionChanged += new EventHandler(cm_PositionChanged); In the handler, if the position change is from outside the grid, move the currentcell.
private void cm_PositionChanged(object sender, EventArgs e)
{
	if(!this.gridDataBoundGrid1.CurrentCell.IsInMoveTo)
	{
		CurrencyManager cm = sender as CurrencyManager;
		if(cm != null)
		{
			int row = this.gridDataBoundGrid1.Binder.PositionToRowIndex(cm.Position);
			this.gridDataBoundGrid1.CurrentCell.MoveTo(row, this.gridDataBoundGrid1.CurrentCell.ColIndex);
		}
	}
}


LP Lev Pelekh February 10, 2006 09:40 PM UTC

I am trying to undo the black color of the selected row in GridDataBoundGrid. I would like it to stay white. I tried setting e.Style.BackColor in the GDBG_PrepareViewStyleInfo event, but doesn''t seem to effect selected rows, they are still black. Any info would be appreciated. Lev


ST stanleyj Syncfusion Team February 13, 2006 05:00 AM UTC

Hi Lev, I do not know what black color you are trying to remove. Here is a code snippet to show setting e.Style.BackColor in the PrepareViewStyleInfo event that changes for the selected rows. this.gridDataBoundGrid1.AlphaBlendSelectionColor = Color.Empty; this.gridDataBoundGrid1.ListBoxSelectionMode = SelectionMode.One; this.gridDataBoundGrid1.ShowCurrentCellBorderBehavior = GridShowCurrentCellBorder.HideAlways; this.gridDataBoundGrid1.PrepareViewStyleInfo += new GridPrepareViewStyleInfoEventHandler(gridDataBoundGrid1_PrepareViewStyleInfo); private void gridDataBoundGrid1_PrepareViewStyleInfo(object sender, GridPrepareViewStyleInfoEventArgs e) { GridCurrentCell cc = gridDataBoundGrid1.CurrentCell; // Highlight the current row if (e.RowIndex > gridDataBoundGrid1.Model.Rows.HeaderCount && e.ColIndex > gridDataBoundGrid1.Model.Cols.HeaderCount && cc.HasCurrentCellAt(e.RowIndex)) { e.Style.BackColor = Color.Pink; e.Style.TextColor = SystemColors.HighlightText; e.Style.Font.Bold = true; } } Best regards, Stanley

Loader.
Live Chat Icon For mobile
Up arrow icon