This is a migrated thread and some comments may be shown as answers.
Column ReadOnly true at EditMode but false at InsertMode
3 Answers 67 Views
This is a migrated thread and some comments may be shown as answers.
Naunton
Top achievements
Rank 1
Naunton asked on 18 Jan 2011, 11:45 AM
Hi all,

I want to set a column to ReadOnly=True at EditMode, but at InsertMode ReadOnly=False. Please advise how to do it.
I did as below but it didn't work. Please help.

Private Sub RadGrid1_ItemCommand(ByVal source As Object, ByVal e As Telerik.Web.UI.GridCommandEventArgs) Handles RadGrid1.ItemCommand
If e.CommandName = RadGrid.EditCommandName Then
            Dim editItem As GridEditableItem = CType(RadGrid1.MasterTableView.GetItems(GridItemType.EditItem)(0), GridEditableItem)
            For Each column As GridColumn In RadGrid1.MasterTableView.Columns
                If column.UniqueName = "POL" Then
                    Dim txtbox As TextBox = CType(editItem (column.UniqueName).Controls(0), TextBox)
                    txtbox.ReadOnly = True
                End If
            Next
End If
End Sub

But I got error  "Index was outside the bounds of the array." at the below code ..
If e.CommandName = RadGrid.EditCommandName Then
            Dim editItem As GridEditableItem = CType(RadGrid1.MasterTableView.GetItems(GridItemType.EditItem)(0), GridEditableItem)

Many Thanks

3 Answers, 1 is accepted

Sort by
0
Accepted
Princy
Top achievements
Rank 1
answered on 18 Jan 2011, 12:52 PM
Hello Naunt,

You can set the ReadOnly property for control in edit/insert mode in ItemdataBound event.

VB.NET:
Protected Sub RadGrid1_ItemDataBound(sender As Object, e As GridItemEventArgs)
    If e.Item.OwnerTableView.IsItemInserted Then
        'item is about to be inserted  and EditMode is 'InPlace'
        If TypeOf e.Item Is GridDataInsertItem Then
            Dim inserItem As GridDataInsertItem = DirectCast(e.Item, GridDataInsertItem)
            Dim txtbox As TextBox = DirectCast(inserItem("POL").Controls(0), TextBox)
            txtbox.[ReadOnly] = False
        End If
    End If
    If Not (TypeOf e.Item Is GridDataInsertItem) AndAlso e.Item.IsInEditMode Then
        'item is about to be edit and EditMode is 'InPlace'
        Dim editItem As GridEditableItem = DirectCast(e.Item, GridEditableItem)
        Dim txtbox As TextBox = DirectCast(editItem("POL").Controls(0), TextBox)
        txtbox.[ReadOnly] = True
    End If
End Sub

Thanks,
Princy.
0
Naunton
Top achievements
Rank 1
answered on 19 Jan 2011, 02:36 AM
Hi Princy,

Many thanks, this work very well.  :)
0
umesh
Top achievements
Rank 1
answered on 22 Apr 2015, 11:44 PM

How can I write that in c#?

 

thanks

Tags
Grid
Asked by
Naunton
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 1
Naunton
Top achievements
Rank 1
umesh
Top achievements
Rank 1
Share this question
or