Home - Forums-.NET - FlyGrid.Net (Windows Forms) - Determining if a particular cell is read only?

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

Determining if a particular cell is read only?
Link Posted: 24-Aug-2006 03:36
This is what I thought.

As I mentioned, I don't want the IsReadOnly event to be raised - this means a lot of work being duplicated.

I just want a property that says whether or not the cell is currently readonly.  The grid would have already raised IsReadOnly - so it should already know if this cell is readonly.

Again, I specifically do not want to duplicate all the work of figuring out if a cell is readonly when painting it.

I really need something from the grid that just knows if the cell is read only.
Link Posted: 24-Aug-2006 03:48
Column.OnIsReadOnly method work as follwing:
calling internal flyGrid.OnIsReadOnly method that do folloing:
1. analysis of node.ReadOnly state, column.ReadOnly state. if result is true - return result.
2. if result is false and FlyGrid.IsReadOnly event has a handler - calling this handler and return result.

If you make certain cells read-only in MakeEditorReadonly - please transfer this code to overriden Column.IsReadOnly method and use this method to determine readonly state of certain cells.
Link Posted: 24-Aug-2006 04:22
I understand how OnIsreadOnly would work.

I already stated several times the problem I have with it.

Here it is again: I am determining whether or not something is read only on a cell by cell basis. That means the IsReadOnly event will always be raised. That means all that code I have in the handler will always be run every single time the cell is painted.

What I am trying to explain to you is that this is highly inefficient. I need to just be able to tell if a cell is read only right now or not, based on what the result was the last time the grid had to determine this.

Can you please provide a way to just examine whether or not a cell is readonly *without* raising the IsReadOnly event?
Link Posted: 24-Aug-2006 08:07
[c#]
public bool CellIsReadOnly(Column col, NodeBase node)
{
  FlyGrid flyGrid = col.this.Owner.GetOwner();
  return node.ReadOnly | col.ReadOnly | (flyGrid.Options & GridOptions.ReadOnly) != 0;
}
Link Posted: 24-Aug-2006 08:33
This does not work.

Some of my cells are read only (I am hadling the IsReadOnly event).

However, CellIsReadOnly always returns false when called from the overriddent paint method.

Tracing through it, IsReadOnly does not get called at all during painting for the grid. It only gets called later when the user tries to interact with a cell.
Link Posted: 24-Aug-2006 09:38
Yes, OnIsReadOnly doesn't called in paint - painter doesn't need to know about readonly state of node.
If you want to use FlyGrid.IsReadOnly event handling - you can use Column.OnIsReadOnly - this method uses the same scheme excluding examining Column.ReadOnly.
but this easy to use:
[c#]
//in column inheritor
public bool CellIsReadOnly(FlyGrid flyGrid, NodeBase node)
{
  if (!this.readOnly)
{
    //this method calling flyGrid.OnIsReadonly and if result is false - FlyGrid.IsReadOnly fired (if handler connected)
    return base.OnIsReadOnly(flyGrid, node);
  }
  return true;
}
Link Posted: 30-Aug-2006 07:51
Most grids will render read-only cells differently then editable cells. When a cell is locked, it typically looks greyed out, etc.

In any case, the only real options are to either re-run the code that figure out whether or not a cell is locked, or to cache that data manually.

Thanks.