Can I apply style to Range of Cells

Hi!

I need to apply some certain style to a range of cells

How to implement it?

1. How to get Range of cells

2. How to assign certain style to all of them at once?

I use Desktop grid

Hi,

We don't implement the method to set style of Range, you could try below codes.

Aspose.Grid.Desktop.Worksheet sheet = gridDesktop1.GetActiveWorksheet();
CellRange cr = sheet.GetLastSelection();
if (cr != null)
{
for(int row = cr.StartRow; row <= cr.EndRow; row++)
{
for(int column = cr.StartColumn; column <= cr.EndColumn; column++)
{
Aspose.Grid.Desktop.GridCell cell = sheet.Cells[row, column];
Style style = cell.GetStyle();
style.Color = Color.Black;
cell.SetStyle(style);
}
}
}

It's not elegant solution

Will u include this feature in future releases?

We will add this feature in a hot fix.

We have implemented 3 methods that set style, font, font color to range of cells in Worksheet class:

Worksheet.SetStyle(CellRange range, Style style);

Worksheet.SetFont(CellRange range, Font font);

Worksheet.SetFontColor(CellRange range, Color color);

You can try these codes:

Aspose.Grid.Desktop.Worksheet sheet = gridDesktop1.GetActiveWorksheet();
CellRange cr = sheet.GetLastSelection();
Style style = new Style(this.gridDesktop1);
style.Color = Color.Black;
sheet.SetStyle(cr, style);
Font font = new Font("Courier New", 12f);
sheet.SetFont(cr, font);
sheet.SetFontColor(cr, Color.Red);

Many Thanks

Can I retrieve CellRange like

CellRange cr =new cr(start_row,start_column,rows,columns);

????

Sure, you can create a CellRange object as you need:

CellRange cr = new CellRange("a1", "b3");

or

CellRange cr = new CellRange(0, 1, 2, 3);

Please try this attached version. Other your requested feature are available in this version.

Thank u very much!!

And what about R1C1 reference style?

Do u plan to support it?

We will support R1C1 reference style in two weeks.

Smile [:)]

Thanks, but could u also add celldoubleclick event for me in future releases? - it's very important!

Tongue Tied [:S]

I think it would be logically approved if u include support for cell_key_pressed event too!!!!

When user double clicks on a cell, the default behavior is to show a edit control to input char.

We have added cell button feature in the attached version, could you use CellButtonClick event to replace celldoubleclick event?

Could you please tell us what feature you use CellKeyPressed event to implement?

We are developing cell validation feature, is this helpful to you?

Well, I don't want user to cut and paste anythin' - so I need to handle some keyboard operations.

Like "CTRL+X" and so on.

What do u mean - when I doubleclick cell - nothin' happens

And in my application I want cell to show/hide some information - it's just a way to pass the problem of row/column groupin' - if u implement row/column groupin' - I won't need this feature!!

Yeah, It's a goog idea to have somethin' like webgrid validation object in destop grid.

It would be wonderful if we could use different validation interfaces like checklistboxes,comboboxes and so on!!

It would be very useful feature.

Hi Kola,

We have implemented CellDoubleClick and CellKeyPressed events.

If you don't want user to copy, cut, paste anything, you should set ShowContextMenu property of GridDesktop false; and handle CellKeyPressed event. CellKeyPressed event provides a CellKeyEventArgs argument which derived from KeyEventArgs class. To prevent GridDesktop from handling the key event, you should set e.Handled = true. Codes like that:

private void gridDesktop1_CellKeyPressed(object sender, CellKeyEventArgs e)
{
if (e.KeyCode == Keys.X && e.Control)
{
e.Handled = true;
}
}

We will release an attached version soon.

Thanks a lot, I’m awaitin new version!!

Please try this attached version.