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.

Color of current cell

Thread ID:

Created:

Updated:

Platform:

Replies:

67332 Aug 14,2007 09:19 AM Dec 31,2007 05:01 AM Windows Forms 6
loading
Tags: GridControl
Lucia Diaconu
Asked On August 14, 2007 09:19 AM

Hello!

I tried to find the answer in the forum, but I could not obtain what I wanted.

I have a virtual grid that allows any selection. I want to set the background color for the selected cells.
I have implemented the PrepareViewStyleInfo event handler:
private void grid_PrepareViewStyleInfo( object sender, GridPrepareViewStyleInfoEventArgs e)
{
if (grid.Selections.Ranges.AnyRangeContains(GridRangeInfo.Cell( e.RowIndex, e.ColIndex)))
e.Style.BackColor = Color.Blue;
}
and it works fine except for the current cell (if I select only one cell or, using multiple selections, for the cell that remains the "current cell")
When selecting multiple cell using the CTRL key, I see the last selected cell becoming blue, than turning back to the default row color (I have alternate row colors).
It seems that this behavior exists because of the RichTextBox used for the current cell (my grid is read-only, so this behavior is not necessary).

What can I do?

Thanks in advance,
Lucia

Rajagopal [Syncfusion]
Replied On August 14, 2007 09:26 PM

Hi Lucia,

Actually when the currentcell is not in the editing state, it generally is part of the selections. It is just that the current cell is not included when the selection rectangle is drawn. This is by design. If you want to see it colored like other selected cells, then you can handle the CellDrawn event and color it there. Please try the code below.

void grid_CellDrawn(object sender, GridDrawCellEventArgs e)
{
GridCurrentCell cc = this.grid.CurrentCell;

if (e.ColIndex == cc.ColIndex && e.RowIndex == cc.RowIndex)
{
SolidBrush br = new SolidBrush(Color.Blue);
e.Graphics.FillRectangle(br, e.Bounds);
br.Dispose();
}
}

Here is a sample showing this
http://websamples.syncfusion.com/samples/Grid.Windows/F67332/main.htm

Let me know if you have any other questions.

Have a nice time.
Regards,
Rajagopal

Lucia Diaconu
Replied On August 15, 2007 09:53 AM

Hi Rajagpal!

I tried your solution and it is not exactly what I need:
1) Selecting with mouse-click:
1.a. at button down, the blue filled rectangle appears (see image SelectedCell_MouseDown)
1.b. at button up, the text appears and the blue color can be seen as a small left and even smaller right margin (see image SelectedCell_MouseUp)
2) selecting with the keyboard's arrow keys it is worse, because the text of the selected cell is not visible anymore (see image SelectedCell_Keyboard)

Something must be incorrect in my cell settings, but I don't know what (I hope you know :-) )

Thanks,
Lucia

I can't post the message, I try without the attachment first...

Lucia Diaconu
Replied On August 16, 2007 10:11 AM

Yesterday I could not attach the zip with the images. Maybe today it will be possible?

Syncfusion_SelectedCellBackColor.zip

Rajagopal [Syncfusion]
Replied On August 16, 2007 10:48 PM

Hi Lucia,

Please refer the sample below that handles the PrepareViewStyleInfo event to color the currentcell when it is a part of selection. This seems to work as expected.

Here is a sample
http://www.syncfusion.com/Support/user/uploads/GC_SelectionColrs1_512fa30e.zip

Let me know if this helps.

Regards,
Rajagopal

Lucia Diaconu
Replied On August 20, 2007 09:13 AM

Hi!
Yes, this did the job.
But it was very strange at first because I wanted to optimize the code and I have changed the initial sequence:
GridControl grid = sender as GridControl;
GridCurrentCell cc = grid.CurrentCell;
if (grid.Selections.Ranges.AnyRangeContains(GridRangeInfo.Cell(e.RowIndex, e.ColIndex)))
{
e.Style.BackColor = Color.DarkBlue;
}
if (e.RowIndex == cc.RowIndex && e.ColIndex == cc.ColIndex)
{
e.Style.BackColor = Color.DarkBlue;
}

into the sequence:
GridControl grid = sender as GridControl;
GridCurrentCell cc = grid.CurrentCell;
if (e.RowIndex == cc.RowIndex && e.ColIndex == cc.ColIndex)
{
e.Style.BackColor = Color.DarkBlue;
}
else
if (grid.Selections.Ranges.AnyRangeContains(GridRangeInfo.Cell(e.RowIndex, e.ColIndex)))
{
e.Style.BackColor = Color.DarkBlue;
}

and it had a very strange behavior:
1. when selecting several cell (e.g. CTRL + mouse or keypad selection), the previously selected cell's background became yellow. After that, a simple new selection left the old selected cell appear blue.
This is kind of strange for me because it seems I don't understand well the behavior of the grid :-((

Anyway, in the "good" order, it was ok.

Thank you!
Lucia


Administrator [Syncfusion]
Replied On December 31, 2007 05:01 AM

Hi Lucia,

Sorry for the delay in getting back to you.

Strange behavior - The background of the selected cell rectangle becomes yellow when the BackColor was set to DarkBlue.

This behavior was common with .NET DataGridView control. The color of the cursor is different from the BackColor we set especially for DarkCyan, DarkBlue, etc., when the cell is in edit mode.

Please refer the sample that compares the behavior of GridControl with DataGridView control and let me know if you have any further questions.

http://websamples.syncfusion.com/samples/Grid.Windows/F67332/Selection/main.htm

Thanks for your patience.

Regards,
Jaya



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.

;