GrapeCity MultiRow Windows Forms Documentation
NewCellPosition Property
Example 


Gets or sets a new current cell position.
Syntax
Public Property NewCellPosition As CellPosition
Dim instance As NewCellPositionNeededEventArgs
Dim value As CellPosition
 
instance.NewCellPosition = value
 
value = instance.NewCellPosition
public CellPosition NewCellPosition {get; set;}

Property Value

A CellPosition object that indicates the new current cell position.
Exceptions
ExceptionDescription
System.InvalidOperationExceptionThe Template is a null reference (Nothing in Visual Basic).
System.ArgumentOutOfRangeExceptionThe assigned CellPosition.SectionIndex is less than 0 or greater than or equal to the section's count.
System.ArgumentException

The assigned CellPosition.CellIndex or CellPosition.CellName cannot be found in the specified Section.Cells.

-or-

The specified Cell cannot be selected.

Remarks

The initial value of the property is the current target cell.

You can change the current target cell by setting the NewCellPosition property value.

If the NewCellPosition is not in the visual area, the cell is scrolled into the visual area.

Example
The following code example shows how to use this property to redirect the new cell position when leaving a cell. To run this example, create a form and add the GcMultiRow control to the form. Add the NewCellPositionNeeded event handler and copy the code to the event handler. Your template should contain two cells named "State" and "Description".
void gcMultiRow1_NewCellPositionNeeded(object sender, NewCellPositionNeededEventArgs e)
        {
            // When user tries to switch current cell to another row.
            // Control checks whether 'State' is 'Delay'. If the 'State' is 'Delay' and the 
            // user did not fill out a description, the current cell changes to 'Description' cell
            // in the same section, and pops up a message box to notify the user to fill out this cell.
            if (e.SectionIndex != e.NewCellPosition.SectionIndex)
            {
                object projectState = gcMultiRow1[e.SectionIndex,"State"].Value;
                object description = gcMultiRow1[e.SectionIndex, "Description"].Value;
                if (description == null || object.Equals(string.Empty, description))
                {
                    if(object.Equals(projectState, "Delay"))
                    {
                        MessageBox.Show("If project state is delay, fill out a description.");

                        e.NewCellPosition = new CellPosition(e.SectionIndex, "Description");
                    }
                }

            }
Private Sub gcMultiRow1_NewCellPositionNeeded(ByVal sender As Object, ByVal e As 
NewCellPositionNeededEventArgs) Handles gcMultiRow1.NewCellPositionNeeded
        ' When the user tries to switch current cell to another row.
        ' Control checks whether 'State' is 'Delay'. If the 'State' is 'Delay' and the  
        ' user did not fill out a description, the current cell changes to 'Description' cell
        ' in the same section, and pops up a message box to notify the user to fill out this cell.
        If e.SectionIndex <> e.NewCellPosition.SectionIndex Then
            Dim projectState As Object = gcMultiRow1(e.SectionIndex, "State").Value
            Dim description As Object = gcMultiRow1(e.SectionIndex, "Description").Value
            If description = Nothing OrElse Object.Equals(String.Empty, description) Then
                If Object.Equals(projectState, "Delay") Then
                    MessageBox.Show("If project state is delay, fill out a description.")

                    e.NewCellPosition = New CellPosition(e.SectionIndex, "Description")
                End If

            End If
        End If
    End Sub
Requirements

Target Platforms: Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2

See Also

Reference

NewCellPositionNeededEventArgs Class
NewCellPositionNeededEventArgs Members

 

 


Copyright © GrapeCity, inc. All rights reserved.