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
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

Color selected line

Thread ID:





23684 Jan 18,2005 07:02 AM UTC Feb 13,2006 05:00 AM UTC WinForms 6
Tags: GridControl
Asked On January 18, 2005 07:02 AM UTC

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

Administrator [Syncfusion]
Replied On 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. 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.

Replied On 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 ?

Replied On 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 ?

Administrator [Syncfusion]
Replied On 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)
		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);

Lev Pelekh
Replied On 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

stanleyj [Syncfusion]
Replied On 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


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.

Please sign in to access our forum

This page will automatically be redirected to the sign-in page in 10 seconds.

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

Live Chat Icon For mobile
Live Chat Icon