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. (Last updated on: November 16, 2018).
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

Simulate new row add with a regular GridControl

Thread ID:

Created:

Updated:

Platform:

Replies:

4959 Jun 11,2003 12:04 AM UTC Jun 16,2003 08:49 PM UTC WinForms 5
loading
Tags: GridControl
Mike O'Connor
Asked On June 11, 2003 12:04 AM UTC

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

Administrator [Syncfusion]
Replied On 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

Mike O'Connor
Replied On 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
> 

Mike O'Connor
Replied On 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

Administrator [Syncfusion]
Replied On 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); }

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

Perfect, thank you! mike

CONFIRMATION

This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon

;