Home - Forums-.NET - FlyGrid.Net (Windows Forms) - Ability to change Selected/SelectedInactive cell brush

FlyGrid.Net (Windows Forms)

.NET Datagrid - Fast, highly customizable, industry standards .NET data grid control for WinForms

This forum related to following products: FlyGrid.Net

Ability to change Selected/SelectedInactive cell brush
Link Posted: 11-May-2006 11:42
I just give you a sample \"how to determine focused cell\".
If you will use IStyleNode implementation, you can notice that OnBeginPaint provides CellDrawInfo instance as parameter and you can use the same technique.

public class CoolNode : Node, IStyledNode
{
  public void OnBeginPaint(CellDrawInfo info)
  {
    Columns cols = info.grid.Columns;
    bool cellFocused = node.Selected && cols.CurrentColumn == info.col;
    //......
  }
}


Your code sample isn't correct either anyways, because dci.currentColumn is of type column and dci.col is int. I don't know how to get the index of currentColumn?


Please attentively read sample - it uses Columns.CurrentColumn type of [int]
Link Posted: 11-May-2006 11:48
I attentively read your sample. However, dci/info.PORT doesn't exist. Thus I assumed you had a typo and meant dci/info.currentColumn.
So, where is PORT?
Link Posted: 11-May-2006 12:54
Sorry for incorrecntess, I've corrected code - port means viewport(FlyGridViewPort),
provided by CellDrawInfo.grid.
Link Posted: 11-May-2006 13:01
this doesn't work?


public void OnBeginPaint(CellDrawInfo info)
        {
            Columns cols = info.grid.Columns;
            if (this.Selected && cols.CurrentColumn == info.col)
                info.customBackColor = Color.Red;
}


info.customBackColor = Color.Red; is never called, even if the cell has focus and becomes highlighted?
I simply want a cell that is clicked on to have a custom drawn border and different background color... can't be that hard (Columns are NOT editable)??
Link Posted: 13-May-2006 10:41
This code works
[c#]
internal class StyledNode : Node, IStyledNode
{
  public StyledNode(object value) : base(value){}
  public StyledNode(NodeBase parent) : base(parent){}

  public void OnBeginPaint(CellDrawInfo info)
  {
    Columns cols = info.grid.Columns;
    if (this.Selected && cols.CurrentColumn == info.col)
      info.customBackColor = Color.Red;
  }

  public void OnEndPaint(CellDrawInfo info)
  {
    info.customForeColor = Color.Empty;
    info.customBackColor = Color.Empty;
  }
}
Link Posted: 13-May-2006 11:34
ok several problems here:

The bottom line of the border doesn't draw:
Columns cols = info.grid.Columns;
            if (this.Selected && cols.CurrentColumn == info.col)
            {
                info.customBackColor = Color.DarkBlue;
                info.g.DrawRectangle(new Pen(Color.Yellow), new Rectangle(info.cellRect.X - 1, info.cellRect.Y -1, info.cellRect.Width +1, info.cellRect.Height + 1));        
            }





If I use info.cellRect.Height + 2, it draws but is too far down and has a gap.

Also, when I have a selected cell and click on another one, the borders don't draw correct again and I want to get rid of the back color for the previously selected cell. How do I do that?

Link Posted: 13-May-2006 11:45
Also, there's another weird bug. When I click on a cell that is editable, a rect is drawn in the upper left corner of the grid on top of the column headers for a short period of time.

EDIT: Actually, this doesn't happen only with editable cells but whenever I click on the top left cell. Then a rect is drawn above the column headers
Link Posted: 13-May-2006 23:51
You should inflate cell rectangle to correctly draw borders.
[c#]
Rectangle cell = info.cellRect;            
if ((info.grid.FlyGrid.Options & GridOptions.ShowHorzLines) != 0)
{
  cell.Height -= info.grid.FlyGrid.LineWidth;
}
if ((info.grid.FlyGrid.Options & GridOptions.ShowVertLines) != 0)
{
  cell.Width -= info.grid.FlyGrid.LineWidth;
}
Link Posted: 14-May-2006 00:06
That doesn't work. With that code no rect is shown at all.
I think it is because the border is drawn before the background color. Thus, the background paints over the border.
Link Posted: 14-May-2006 07:40
But you can draw border in OnEndPaint:
[c#]
public void OnEndPaint(CellDrawInfo info)
{
  Columns cols = info.grid.Columns;
  if (this.Selected && cols.CurrentColumn == info.col)
  {
    using (Pen pen = new Pen(Color.Red, 1))
    {
      Rectangle cell = info.cellRect;
      if ((info.grid.FlyGrid.Options & GridOptions.ShowHorzLines) != 0)
      {
        cell.Height -= info.grid.FlyGrid.LineWidth;
      }
      if ((info.grid.FlyGrid.Options & GridOptions.ShowVertLines) != 0)
      {
        cell.Width -= info.grid.FlyGrid.LineWidth;
      }
      info.g.DrawRectangle(pen, cell);
    }
  }
  //clear custom info
  info.customForeColor = Color.Empty;
  info.customBackColor = Color.Empty;
}