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.
Syncfusion Feedback

Changing the appearance of cell selections

Thread ID:

Created:

Updated:

Platform:

Replies:

48463 Aug 28,2006 09:51 PM UTC Aug 30,2006 01:06 PM UTC Windows Forms 6
loading
Tags: GridControl
Administrator [Syncfusion]
Asked On August 28, 2006 09:51 PM UTC

I''ve been trying to change the way a cell is painted when being selected. It appears the default behaviour is some kind of alphablending but I would like to change that to a specific color for example orange. Is this possible?

Also if I were to select cell (0,0) could I automatically select cell (0,1) for example? Again painting the additional cell in the same manor as above.

Thanks

Administrator [Syncfusion]
Replied On August 28, 2006 09:51 PM UTC

Just for clarification not just the selection of a single cell but when you click and hold down the mouse to select multiple cells.

>I''ve been trying to change the way a cell is painted when being selected. It appears the default behaviour is some kind of alphablending but I would like to change that to a specific color for example orange. Is this possible?

Also if I were to select cell (0,0) could I automatically select cell (0,1) for example? Again painting the additional cell in the same manor as above.

Thanks

Administrator [Syncfusion]
Replied On August 28, 2006 11:59 PM UTC

I managed to resolve the alphablending issue but am stuck trying to select multiple cells. The issue is that in the SelectionChanged event the e.Range.Top always starts at 0 regardless of the relative position you clicked on the grid. So for example i click on cell (3,3) on the grid e.Range.Top would = 0 and e.Range.Left would = 0.

How can I get the actual row index and column index from this GridRangeInfo object? Below is the snippet that i''m using.

private void gdgVendCal_SelectionChanged(object sender, Syncfusion.Windows.Forms.Grid.GridSelectionChangedEventArgs e)
{

for (int i = e.Range.Top; i <= e.Range.Bottom; i++)
for (int j = e.Range.Left; j <= e.Range.Right; j++)
{
// If it''s an even row on the grid include the row below in the selection
if(i % 2 == 1 && !e.Range.IntersectsWith(GridRangeInfo.Cell(i - 1,j)))
{ this.gdgVendCal.Selections.Add(GridRangeInfo.Cell(i - 1, j)); this.gdgVendCal.InvalidateRange(GridRangeInfo.Col(j));
}
else if(!e.Range.IntersectsWith(GridRangeInfo.Cell(i + 1,j)))
{
this.gdgVendCal.Selections.Add(GridRangeInfo.Cell(i + 1, j));
this.gdgVendCal.InvalidateRange(GridRangeInfo.Col(j));
}
}
}

grid_selection0.zip

Administrator [Syncfusion]
Replied On August 29, 2006 08:00 AM UTC

Hi Mike,

To change the default selection color, you can set the AlphaBlendSelectionColor property to any user desired color.

this.gridControl1.AlphaBlendSelectionColor = Color.Orange;


set the AllowSelection property, that defines the selection behavior of the grid

this.gridControl1.AllowSelection = GridSelectionFlags.Any; // to select multiple cells


By default, when you try to select cell(0,0) in grid, entire table will get selected. If you dont want this behavior and want to select something else, then SelectionChanging event can be handled.

private void gridControl1_SelectionChanging(object sender, GridSelectionChangingEventArgs e)
{
if(e.Range.IsTable) // checking if cell(0, 0) is selected
{
e.Cancel = true;
this.gridControl1.Selections.Add(GridRangeInfo.Cell(0, 1));
}
}

Let me know if you have any other questions.
Regards,
Rajagopal

Administrator [Syncfusion]
Replied On August 29, 2006 03:22 PM UTC

The problem is not selecting cell (0,0) but rather if I select any other cell besides that one for example cell (3,3).

The gridControl1_SelectionChanging event will show that i''ve selected (0,0) ie

e.Range.Top = 0
e.Range.Left = 0

If I select multiple cells again the e.Range values start from (0,0) regardless of where I click on the grid.

I want to retrieve the actual row and column index on the grid not the index within the range.

>Hi Mike,

To change the default selection color, you can set the AlphaBlendSelectionColor property to any user desired color.

this.gridControl1.AlphaBlendSelectionColor = Color.Orange;


set the AllowSelection property, that defines the selection behavior of the grid

this.gridControl1.AllowSelection = GridSelectionFlags.Any; // to select multiple cells


By default, when you try to select cell(0,0) in grid, entire table will get selected. If you dont want this behavior and want to select something else, then SelectionChanging event can be handled.

private void gridControl1_SelectionChanging(object sender, GridSelectionChangingEventArgs e)
{
if(e.Range.IsTable) // checking if cell(0, 0) is selected
{
e.Cancel = true;
this.gridControl1.Selections.Add(GridRangeInfo.Cell(0, 1));
}
}

Let me know if you have any other questions.
Regards,
Rajagopal

Administrator [Syncfusion]
Replied On August 29, 2006 04:05 PM UTC

I''ve looked at a previous example one of your staff provided using the SelectionChanged and it properly returns the row index and column index relative to where you clicked on the grid.

Is it possible that because i''m using custom cells and overriding the cell_draw event that this would somehow cause SelectionChanged to return (0,0) for every cell clicked?

Administrator [Syncfusion]
Replied On August 30, 2006 01:06 PM UTC

Mike,

We do custom coloring without alpha blending in our grid as well here''s how we do it:

In the PrepareViewStyleInfo (and possibly in QueryCellInfo as well), we simply do something like:

if (grid.Selections.Ranges.AnyRangeContains(GridRangeInfo.Cell(e.RowIndex, e.ColIndex))
{
e.Style.BackColor = _selectedCellColor;
}

The if statement simply determines if the cell currently being drawn is in any of the selection ranges and if so, then change the background color to our selection color.

Pete

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.

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

;