Home - Forums-.NET - FlyGrid.Net (Windows Forms) - Problem: TreeViewNode Selection and Coordinates

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

Problem: TreeViewNode Selection and Coordinates
Link Posted: 09-Aug-2006 13:00
I (Right click and) select a TreeViewNode in a grid with a single TreeViewColumn.

Then I call the following routine to get the cell Rectangle:

    public static Rectangle GetCellRectangle(NineRays.Windows.Forms.FlyGrid flyGrid, NodeBase node, Column column)
    {
      FlyGridViewPort viewPort = flyGrid.ActiveRootPort;
      int row = viewPort.Rows.GetRowFromNode(node);
      if (row != -1) //node is visible
      {
        int col = viewPort.Columns.GetColumnCellIndex(column);
        if (col != -1)//column is visible
        {
          return viewPort.GetRectangle(viewPort.Bounds, row, col);
        }
      }

      return Rectangle.Empty;
    }


No matter which node I Right select (column index is resolved, correctly, as 0), the Rectangle always comes back as:

X = 0, Y = 0, Width = 0, Height = 20

(The Bounds of the ActiveViewPort are returned as:
X = 1, Y = 1, Width = 384, Height = 311)
Link Posted: 09-Aug-2006 14:01
I also notice that if I scroll the grid vertically, then GetCellRectangle - via the statement
return viewPort.GetRectangle(viewPort.Bounds, row, col)
- thereafter returns
Rectangle.Empty
until I scroll the grid back up to top again.
Link Posted: 10-Aug-2006 00:18
But why you use this method, when you can use FlyGrid.GetHitTestInfoAt to determine ViewPort(FlyGridViewPort), column index (and than Column), row index(and extract NodeBase)?
Link Posted: 10-Aug-2006 07:23
Two things:

(1) I already know the NodeBase I've selected: I wanted node / column 0 / cell screen rectangle. What you're suggesting is that I use a generic mousedown event and go in the other direction, from coordinates to FlyGrid.

(2) The code I was using came from NineRays (this message board), but as far as I know (I may be wrong in this) it doesn't seem to work; I wondered why, that's all.
Link Posted: 10-Aug-2006 07:38
Your code is a little bit incorrect (exchange row and col args in viewPort.GetRectangle):
[c#]
public static Rectangle GetCellRectangle(NineRays.Windows.Forms.FlyGrid flyGrid, NodeBase node, Column column)
{
  FlyGridViewPort viewPort = flyGrid.ActiveRootPort;
  int row = viewPort.Rows.GetRowFromNode(node);
  if (row != -1) //node is visible
  {
    int col = viewPort.Columns.GetColumnCellIndex(column);
    if (col != -1)//column is visible
    {
      return viewPort.GetRectangle(viewPort.Bounds, col, row);
    }
  }

  return Rectangle.Empty;
}

This code will work.