This is a migrated thread and some comments may be shown as answers.

Cancel cell editing

1 Answer 110 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Sean
Top achievements
Rank 1
Sean asked on 14 Oct 2009, 06:47 PM
Hello,
I have a grid with certain fields that are not editable depending on the value of other fields on that row.  The best way I came up with to handle this was to wire up the CellBeginEdit event, and if the field is not allowed to be edited, then cancel the event.

 Private Sub rgvLines_CellBeginEdit(ByVal sender As ObjectByVal e As Telerik.WinControls.UI.GridViewCellCancelEventArgs) Handles rgvLines.CellBeginEdit  
 
        Select Case e.ColumnIndex  
 
            Case rgvLines.Columns("MFG_ENTITY_ID").Index  
 
                Dim lineCategoryTypeId As Integer 
                Dim lineCategoryShortName As String = Nothing 
 
                'Get the Line Category short name  
                 lineCategoryTypeId = CType(rgvLines.CurrentRow.Cells("LINE_CATEGORY_TYPE_ID").Value, Integer)  
                 lineCategoryShortName = GlobalMethods.GetTypeDefShortNameForTypeID(lineCategoryTypeId)  
 
                  If lineCategoryShortName = AppDefs.LineCategoryShortName.Group  
 
                       e.Cancel = True 
 
                  End if   
 
          End Select 
 
    End Sub 

 

This all works fine but the problem that I am having is that if the user has tabbed into this cell, then focus still stays with the cell that editing was cancelled for.  The default behavior is for tabbing to skip over read-only columns.  So once I cancel the CellBeginEdit event, how can I get to the next editable cell?  Is it possible to simulate the tab key press programmatically?

Thanks,
Sean

1 Answer, 1 is accepted

Sort by
0
Robert
Top achievements
Rank 1
answered on 16 Oct 2009, 07:00 PM
Hi Sean,

You can probably set this up by using the IsCurrent property provided on both the Column and Row objects. These properties can be used set the currently focused cell.
            radGridView1.Rows[2].IsCurrent = true
            radGridView1.Columns[2].IsCurrent = true


For example, if i wanted to skip over selecting the second column, I could do this:
        private void radGridView1_CurrentCellChanged(object sender, Telerik.WinControls.UI.CurrentCellChangedEventArgs e) 
        { 
             
            if (radGridView1.CurrentCell != null
            { 
                if (radGridView1.CurrentCell.ColumnIndex == 1) 
                { 
                    radGridView1.Columns[radGridView1.CurrentCell.ColumnIndex + 1].IsCurrent = true
                } 
            } 
        } 

I hope this information helps.

- Robert

Tags
GridView
Asked by
Sean
Top achievements
Rank 1
Answers by
Robert
Top achievements
Rank 1
Share this question
or