Home - Forums-.NET - FlyGrid.Net (Windows Forms) - How to programmatically set focus on cell for edit

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

How to programmatically set focus on cell for edit
Link Posted: 16-Jun-2006 03:03
[c#]
internal class MyGrid : FlyGrid
{
  public MyGrid()
  {
  }
  protected override bool ProcessCmdKey(ref Message msg, Keys keyData)
  {
    bool res = base.ProcessCmdKey(ref msg, keyData);
    if (keyData == Keys.Return)
    {
      if (ActiveRootPort.EndEdit(true))//commit changes
      {
        MyNode newNode = new MyNode(new object[] { 1, DateTime.Now });
        ActiveRootPort.Rows.Items.Add(newNode);

        this.Selected = newNode;
        return true;
      }
    }
    return base.ProcessCmdKey(ref msg, keyData);    
  }
}

Link Posted: 16-Jun-2006 09:29
I can't use that because then it only works when enter key is pressed. It should just as well work when the user leaves the cell by mouse.
Link Posted: 16-Jun-2006 10:30
But if you click by mouse - you'll select another cell, even if you add new node and select/focus it.
Link Posted: 16-Jun-2006 11:34
I don't follow what you're trying to say?

overriding ProcessCmdKey only triggers the code when the enter key (for example) is pressed...
OnNodeCellChanging triggers when enter key is triggered or the selected cell is changed and a different value was entered.
So rather than giving an alternate solution, why doesn't the \"normal\" way work?
Link Posted: 18-Jun-2006 10:30
There are several reasons why I need to do this in OnNodeCellChanging rather than ProcessCmdKey (e.g. I need to disallow the cell change when the entered value is incorrect). So, is there a bug or am I doing something wrong?
Link Posted: 18-Jun-2006 12:34
No, you can validate entered data in OnNodeCellChanging, but can't change focus of node when data is not commited.
We're trying to find solution for this problem.
Link Posted: 22-Jun-2006 01:01
We've found solution of your problem.
This code you can use with the nearest update of FlyGrid.Net:
[c#]
internal class MyGrid : FlyGrid
{
  public MyGrid()
  {
  }
  protected override bool CommitText(FlyGridViewPort port, string text)
  {
    bool res = base.CommitText(port, text);
    if (res)
    {
      MyNode newNode = new MyNode(new object[] { 1, DateTime.Now });
      port.Rows.Items.Add(newNode);
      this.Selected = newNode;
    }
    return res;
  }
}
Link Posted: 22-Jun-2006 01:23
great thx. But why do you limit the commit to a string? Why not commit an object?
Link Posted: 22-Jun-2006 04:10
Commit to object nested in CommitText, after conversion by column from text. Results of this commit you receiving by calling
[c#]
bool res = base.CommitText(port, text);