We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date

Simulate new row add with a regular GridControl

Hi, I'm looking to simulate MS Access-type functionality with a regular (unbound) GridControl, where a user can press the Tab key on the last column of the last row and have a new row created underneath. The event handler I have is apparently wrong as it's not firing. Can someone point me in the right direction? Would this be a cell-level KeyPress event as opposed to a GridControl KeyPress? Thanks much. Private Sub GridControl1_KeyPress(ByVal sender As System.Object, ByVal e As KeyPressEventArgs) Handles GridControl1.KeyPress If e.KeyChar = vbTab Then Dim cc As GridCurrentCell 'gRowCount is set to the total # of grid rows If cc.RowIndex = gRowCount And cc.ColIndex = 2 Then gRowCount += 1 GridControl1.Rows.InsertRange(gRowCount, 1) End If End If End Sub

5 Replies

AD Administrator Syncfusion Team June 11, 2003 05:02 AM UTC

If you set the WrapCellCellBehavior to move to the next control on the form, the WrapCellNextControlInForm event will be raised when you try to tab off the last cell. In the handler, you can increment the rowcount, explicitly move the current cell, and cancel the event to get the behavior you want.
Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Load
	Me.GridControl1.Model.Options.WrapCellBehavior = GridWrapCellBehavior.NextControlInForm
End Sub

Private Sub GridControl1_WrapCellNextControlInForm(ByVal sender As Object, ByVal e As Syncfusion.Windows.Forms.Grid.GridWrapCellNextControlInFormEventArgs) Handles GridControl1.WrapCellNextControlInForm
	Me.GridControl1.RowCount += 1
	Me.GridControl1.CurrentCell.MoveTo(Me.GridControl1.RowCount, 1)
	e.Cancel = True
End Sub


MO Mike O'Connor June 13, 2003 04:04 PM UTC

Hi, sorry for the newbie questions but I've looked for this one and can't find it discussed prior. GridWrapCellBehavior.NextControlInForm works great as far as adding the new row, but the input focus always heads back to cell(1,1) despite the following .MoveTo. Is there some sort of overriding behavior for the grid that is defaulting to this action? As your code has, I want to set the focus to the first column of the new row for additional input. Thanks again for your great help. mike > If you set the WrapCellCellBehavior to move to the next control on the form, the WrapCellNextControlInForm event will be raised when you try to tab off the last cell. In the handler, you can increment the rowcount, explicitly move the current cell, and cancel the event to get the behavior you want. > >
> Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Load
> 	Me.GridControl1.Model.Options.WrapCellBehavior = GridWrapCellBehavior.NextControlInForm
> End Sub
> 
> Private Sub GridControl1_WrapCellNextControlInForm(ByVal sender As Object, ByVal e As Syncfusion.Windows.Forms.Grid.GridWrapCellNextControlInFormEventArgs) Handles GridControl1.WrapCellNextControlInForm
> 	Me.GridControl1.RowCount += 1
> 	Me.GridControl1.CurrentCell.MoveTo(Me.GridControl1.RowCount, 1)
> 	e.Cancel = True
> End Sub
> 


MO Mike O'Connor June 16, 2003 07:06 PM UTC

Hi, can anyone respond to this? GridControl1.ForceCurrentCellMoveTo = True doesn't change what happens here (focus moving back to cell 1,1). thanks, mike


AD Administrator Syncfusion Team June 16, 2003 08:43 PM UTC

So when you tab off the end of the grid, you want to move to the next control, but you want the currentcell set to the first column of the last row. Is this correct? If so, try this. 1) set tje WrapCellBehavior and add a handler for the WrapCellNextControlInForm event. this.gridDataBoundGrid1.Model.Options.WrapCellBehavior = GridWrapCellBehavior.NextControlInForm; this.gridDataBoundGrid1.WrapCellNextControlInForm += new GridWrapCellNextControlInFormEventHandler(this.gridDataBoundGrid1_WrapCellNextControlInForm); 2) In the event handler, cancel the grid's actions, and do things yourself. private void gridDataBoundGrid1_WrapCellNextControlInForm(object sender, GridWrapCellNextControlInFormEventArgs e) { this.gridDataBoundGrid1.CurrentCell.MoveTo(this.gridDataBoundGrid1.Model.RowCount, 1); e.Cancel = true; this.SelectNextControl(this.gridDataBoundGrid1, true, true, false, true); }


MO Mike O'Connor June 16, 2003 08:49 PM UTC

Perfect, thank you! mike

Loader.
Up arrow icon