Home Forums WinForms controls Xceed Grid for WinForms Automatically add a new row Reply To: Automatically add a new row

User (Old forums)
Member
Post count: 23064

You can try using the KeyUp event on the DataRowTemplate, and do something like the following in the event handler :

private void Form1_Load( object sender, EventArgs e )

{

    dataRowTemplate1.KeyUp +=

new KeyEventHandler( dataRowTemplate1_KeyUp );

}

private bool secondEnter = false;

void dataRowTemplate1_KeyUp( object sender, KeyEventArgs e )

{

    if( e.KeyCode == Keys.Down )

    {

        Xceed.Grid.

DataRow row = sender as Xceed.Grid.DataRow;

        if( row != null )

        {

            ReadOnlyDataRowList rowList = gridControl1.GetSortedDataRows( true );

            if( rowList.IndexOf( row ) == rowList.Count – 1 && secondEnter )

            {

                row = gridControl1.DataRows.AddNew();

                row.EndEdit();

                gridControl1.MoveCurrentRow(

VerticalDirection.Down );

                gridControl1.SelectedRows.Clear();

                gridControl1.SelectedRows.Add( row );

            }

            else if( rowList.IndexOf( row ) == rowList.Count – 1 )

                secondEnter =

true;

            else

                secondEnter =

false;

        }

    }

}

Imported from legacy forums. Posted by André (had 858 views)