Welcome to the Xceed Community Sign in | Join | Help
Community Search  

Insertion row confusion

Sort Posts: Previous Next
  •  07-04-2008, 12:19 AM Post no. 13425

    Insertion row confusion

    Just started working with the grid control for the first time. I'm excited, but I don't understand how to make an Insertion Row do an insert into my bound data object. I just keep typing in it and nothing is ever inserted. Need some help....

    Filed under:
  •  07-04-2008, 11:26 AM Post no. 13432 in reply to 13425

    Re: Insertion row confusion

    What type of data object are your referring to?  For example, if you are using a DataSet that is filled from a DataTable in a Database, when inserting rows through the gird, the DataSet will contain the new row, but not the DataTable (this is how the .NET binding mechanism works).  You will need to manually call the update method for the DataTable to be updated with the new row.


    André
    Software Developer and Tech Support
    Xceed Software Inc.
  •  07-04-2008, 12:04 PM Post no. 13435 in reply to 13432

    Re: Insertion row confusion

    My problem is more fundamental. When I type something in an insertion row, I'm expecting for a new (blank) row to appear and for the row I entered to be appended to the grid when I tab off the insertion row's last cell. Instead, focus wraps to the first cell, the row stays in edit mode, and no row is appended. It's behavior I've never seen in a grid control before. (My experience being Microsoft's built-in DataGridView and Microsoft Access datasheet views.)

     You're quite right that updating the underlying data source is a separate question. But I don't care about that right now. All I want to see is a row appended to the grid when I enter one. I'll worry about saving it later.

  •  07-05-2008, 7:42 AM Post no. 13439 in reply to 13435

    Re: Insertion row confusion

    Just to prevent any wild goose chasing--I think the problem here is with my data binding scheme after all--and not the grid.

    That said, I'm still a little baffled by the way inserts work. I would expect that tabbing off the last cell in the insert row would trigger the insert. Instead, tabbing off the last cell just wraps you back to the first cell. I found that the pressing the down arrow causes an insert, which I don't find intuitive. I'd appreciate a comment/explanation of that behavior.

  •  07-09-2008, 3:23 PM Post no. 13481 in reply to 13439

    Re: Insertion row confusion

    You can handle the KeyUp event, and call EndEdit() on the InsertionRow to commit the changes (thus to add the row to the grid).  Note however that you need to add the handler on the first cell, not the last one, because the Tab key is raised on the next cell from the one on which you are when pressing the Tab key.

    e.g.:

    private void Form1_Load(object sender, EventArgs e)

    {

        insertionRow1.Cells[ "First Column" ].KeyUp += new KeyEventHandler( FirstCell_KeyUp );

    }

    void FirstCell_KeyUp( object sender, KeyEventArgs e )

    {

        if( e.KeyCode == Keys.Tab )

        {

            insertionRow1.EndEdit();

        }

    }


    André
    Software Developer and Tech Support
    Xceed Software Inc.
  •  07-10-2008, 12:51 PM Post no. 13506 in reply to 13481

    Re: Insertion row confusion

    This can also be done by using the QueryInputKey on the CellEditorManager of the last column.

    e.g.:

    private void Form1_Load(object sender, EventArgs e)

    {

        gridControl1.Columns[ "Last column" ].CellEditorManager.QueryInputKey += new QueryEditorInputKeyEventHandler(CellEditorManager_QueryInputKey);

    }

    void CellEditorManager_QueryInputKey( object sender, QueryEditorInputKeyEventArgs e )

    {

        if( e.Cell.GetType() == typeof( InsertionCell ) )

        {

            if( e.KeyData == Keys.Tab )

            {

                insertionRow1.EndEdit();

            }

        }

    }


    André
    Software Developer and Tech Support
    Xceed Software Inc.
View as RSS news feed in XML
Contact | Site Map | Reviews | Legal Terms of Use | Trademarks | Privacy Statement Copyright 2008 Xceed Software Inc.