Home - Forums-.NET - FlyGrid.Net (Windows Forms) - SwitchToEditMode

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

SwitchToEditMode
Link Posted: 26-Feb-2006 20:42
Hi,
How can i go to edit mode programaticly?

not only by mouse click.


thanks,
Guy
Link Posted: 27-Feb-2006 04:18
Methods BeginEdit/EndEdit will available in the nearest FlyGrid update:
and you can use follwing code construction to attempt to editing state:
[c#]
//this example show how to start editing cell specified by the row #1 and column #0
flyGrid.ActivePort.BeginEdit(
        flyGrid.ActivePort.Rows.GetNodeFromRow(1),
        flyGrid.ActivePort.Columns.VisibleColumns[0]);
Link Posted: 16-May-2006 08:20
I tried using the following to change change the cell being edited.
        ActivePort.EndEdit(True)
        ActivePort.BeginEdit(row, col)

EndEdit() caused the data in the active cell to be saved (which is what I wanted).

BeginEdit() caused the selected row to change to the specified row. However, it did not cause the specified cell to enter edit mode.
Link Posted: 16-May-2006 08:54
I've checked this problem.
Please check that column is used in BeginEdit is editable (not ReadOnly) and FlyGrid is editable (GridOptions.ReadOnly excluded from flyGrid.Options).
Test code:
[c#]
private void beginEditMnu_Click(object sender, System.EventArgs e)
{
  if (treeviewGrid.Selected != null)
  {
    //get next node for editing
    NodeBase nextNode = treeviewGrid.Selected.GetNext() as NodeBase;
    if (nextNode != null)
    {
      treeviewGrid.ActivePort.BeginEdit(node, treeviewGrid.Columns.Items[0]);
    }
  }
}

private void endEditMnu_Click(object sender, System.EventArgs e)
{
  treeviewGrid.ActivePort.EndEdit(true);
}

Link Posted: 16-May-2006 09:20
Both the grid and column are editable. I am trying to \"improve\" keyboard navigation for the grid. I created a derived grid and overrode the ProcessCmdKey method, as follows. The implementation is incomplete. However, it should change change the cell being edited when the user selects the up or down arrow key.

    Protected Overrides Function ProcessCmdKey( _
        ByRef m As Message, _
        ByVal KeyData As Keys) As Boolean

        Dim lastRow As Integer = Rows.Items.Count - 1
        Dim row As Integer = Selected.Index
        Dim col As Integer = Columns.CurrentColumn

        If KeyData = Keys.Down Or KeyData = Keys.Return Then
            If row < lastRow Then
                row += 1
            Else
                row = 0
            End If
        ElseIf KeyData = Keys.Up Then
            If row > 0 Then
                row -= 1
            Else
                row = lastRow
            End If
        ElseIf KeyData = Keys.Tab Then
        ElseIf KeyData = (Keys.Shift Or Keys.Tab) Then
        Else
            Return MyBase.ProcessCmdKey(m, KeyData)
        End If

        ActivePort.EndEdit(True)
        ActivePort.BeginEdit(row, col)

        Return True
    End Function

I also want all of the text in the cell to be selected when the user starts editing it. I was able to do that by creating the following derived Column. Is there a better way to do it?

    Private Class FlyingColumn
        Inherits Grids.Column

        Private editor As TextBox = Nothing

        Public Sub New(ByVal name As String, ByVal fieldName As String)
            MyBase.New(name, fieldName)
        End Sub

        Protected Overrides Sub OnEditorSetup(ByVal editor As System.Windows.Forms.TextBox)
            editor.SelectAll()
            Me.editor = editor
        End Sub

        Public Overrides Sub OnMouseUp(ByVal hi As NineRays.Windows.Forms.Grids.HitTestInfo, ByVal node As NineRays.Windows.Forms.Data.NodeBase, ByVal button As System.Windows.Forms.MouseButtons, ByVal pt As System.Drawing.Point)
            If Not editor Is Nothing Then
                editor.SelectAll()
                editor = Nothing
            End If
        End Sub
    End Class
Link Posted: 16-May-2006 09:39
But for what purposes you're improving keyboard navigation?
If columns are editable, editor is always active, if you need to use tabs just include GridOptions.WantTabs option into flyGrid.Options.
You can use F2 key to start editing or press any key to activate editor and type text, and text in editor will selected all after F2 pressing and replaced after pressing any char key by typed char symbol.
Link Posted: 17-May-2006 09:06
The behavior of FlyGrid with WantTabs and F2 appears to be very similar to that of Microsoft Excel. That was probably a good choice on your part. However, it is not the behavior that we want. What we want is:
[list]All cell navigation keys:
[list]Commit the current edit
Move in the specified direction to the next editable cell
Enter edit mode on that cell (without having to press F2)
Select all of the content of that cell[/list:u]
Down and Up Arrow are treated as cell navigation keys in edit mode
Return is equivalent to Down Arrow[/list:u]
I have been able to implement some of the specified behavior. However, I haven't been able to get ActivePort.BeginEdit() to enter edit mode within the ProcessCmdKey() method.

FYI, the table that I am working on is unusual in that all columns but the last are read-only and some of the rows in the table are also read-only.
Link Posted: 17-May-2006 10:20
I've tried to reproduce problem and used following class (copy of your code, but in c# and some tricks(see the OnMouseClick method)):
[C#]
public class ExtGrid : FlyGrid
{
  protected override bool ProcessCmdKey(ref Message msg, Keys keyData)
  {
    int lastRow = Rows.Items.Count -1;
    int row  = Selected.Index;
    int col = Columns.CurrentColumn;
    if(keyData == Keys.Down || keyData == Keys.Return)
    {
      if (row < lastRow)
        row++;
      else
        row = 0;
    }
    else if (keyData == Keys.Up)
    {
      if (row > 0)
        row--;
      else
        row = lastRow;
    }
    else
    {
      return base.ProcessCmdKey (ref msg, keyData);
    }
    ActivePort.EndEdit(true);
    ActivePort.BeginEdit(row, col);
    return true;
  }

  //this method uses a little trick to call SelectAll on internal editor.
  protected override bool OnMouseClick(FlyGridViewPort port, NodeBase node, int col, int x, int y, int count, System.Windows.Forms.MouseButtons button)
  {
    bool res =  base.OnMouseClick (port, node, col, x, y, count, button);
    if (res)
    {
      TextBox editor = (this as IServiceProvider).GetService(typeof(NineRays.Windows.Forms.Grids.IEditSelectionService)) as TextBox;
      if (editor != null && editor.Visible)
      {
        editor.SelectAll();
      }
    }
    return res;
  }
}


And this code meets all your requirements (without using SetupEditor in columns), BeginEdit works correctly - shows editor and selects contents.
I've tried on the latest v1.4.0.6 version.
Link Posted: 17-May-2006 11:36
Thank you for your prompt responses and suggestions!

To determine the product version, I examined the Product Version property of NineRays.FlyGrid.DLL. It says 1.4.0.40558. The format looks different from the one you listed (v1.4.0.6). Do I need to look elsewhere?

ActivePort.BeginEdit() still isn't working for me.
When I use the arrow key to move up or down the column, all of the cells in the column behave as if they are read-only cells. I.e., the writable cells have the same appearance as the read-only cells and they don't respond typed values or F2. However, if I type the Left Arrow key when a writable cell is selected, the cell starts behaving as if it is writable.

FYI, I am using the following to determine whether the cell is read-only.
    Private Function FlyGrid1_IsReadOnly(ByVal sender As System.Object, ByVal node As NineRays.Windows.Forms.Data.NodeBase) As Boolean Handles FlyGrid1.IsReadOnly
        Dim row As DataRow = node.Value.Row

        Return DetermineWhetherARowIsReadOnly(row)
    End Function


P.S.

Is the following the equivalent Visual Basic syntax for your OnMouseClick() method? When I try it, the debugger shows that editor is Nothing.

    Dim res As Boolean = MyBase.OnMouseClick(port, node, col, x, y, count, Button)
    Dim editor As TextBox = GetService(GetType(NineRays.Windows.Forms.Grids.IEditSelectionService))

        If Not editor Is Nothing AndAlso editor.Visible Then
            editor.SelectAll()
            Return res
        End If
Link Posted: 17-May-2006 11:46

Is the following the equivalent Visual Basic syntax for your OnMouseClick() method? When I try it, the debugger shows that editor is Nothing.


Extract explicitly IServiceProvider from this(Me):

Dim res As Boolean = MyBase.OnMouseClick(port, node, col, x, y, count, Button)
Dim isp As IServiceProvider = CType(Me, IServiceProvider))
Dim editor As TextBox = isp.GetService(GetType(NineRays.Windows.Forms.Grids.IEditSelectionService))

If Not editor Is Nothing AndAlso editor.Visible Then
  editor.SelectAll()
Return res
End If