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

How to get the column in prerender event

4 Answers 213 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Myriam
Top achievements
Rank 1
Myriam asked on 19 May 2009, 07:40 PM

Public Sub RadGrid1_PreRender(ByVal sender As ObjectByVal e As System.EventArgs) Handles RadGrid1.PreRender  
        
        If Not IsPostBack Then 
            For Each item As GridItem In RadGrid1.MasterTableView.Items  
                If TypeOf item Is GridEditableItem Then 
 
                    Dim editableItem As GridEditableItem = CType(item, GridDataItem)  
 
                    'TRY to find my column YEAR here but I'm not able  
                    If editableItem.ID = "YEAR" Then 
                        editableItem.Edit = True 
                    End If 
 
                End If 
 
            Next 
            RadGrid1.Rebind()  
        End If 
    End Sub 

Hello
I have a radgrid which is based on a crossed table query. I set the autoGenerateColumn property to true as I don't know the field's name when I execute it. I would like to put a column (which I know the name) in edit mode. But only that column. I can't set the others columns to readonly as I don't know their names. I tried the code above but the editableItem.Id is alway = nothing.
Can someone help me please

4 Answers, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 1
answered on 20 May 2009, 04:19 AM
Hi Myriam,

Set the ReadOnly property of all the columns other than the desired(year)column in ColumnCreated event. Then in the PreRender event you may set the Grid in edit mode.

VB:
 
 Protected Sub RadGrid1_ColumnCreated(ByVal sender As ObjectByVal e As GridColumnCreatedEventArgs) 
     If (e.Column.ColumnType = "GridBoundColumn"AndAlso (e.Column.UniqueName <> "Year"Then 
         Dim bndcol As GridBoundColumn = DirectCast(e.Column, GridBoundColumn) 
         bndcol.[ReadOnly] = True 
     End If 
 End Sub 


 
 Protected Sub RadGrid1_PreRender(ByVal sender As ObjectByVal e As EventArgs) 
     For Each item As GridDataItem In RadGrid1.MasterTableView.Items 
         item.Edit = True 
     Next 
     RadGrid1.MasterTableView.Rebind() 
 End Sub 
 

Thanks
Shinu


0
Myriam
Top achievements
Rank 1
answered on 20 May 2009, 12:23 PM
almost!
it's working but when the values are null  i'm losing all gridlines around the cell.
Does it have a solution?
I tried to put gridlines="both" but doesn't change anything
Thanks
0
Myriam
Top achievements
Rank 1
answered on 20 May 2009, 01:18 PM
Me again...
Also...How can I put the textbox of the column smaller? (Note: I just know the first 3 caracters of the name of my column)
 Private Sub RadGrid1_ColumnCreated(ByVal sender As ObjectByVal e As Telerik.Web.UI.GridColumnCreatedEventArgs) Handles RadGrid1.ColumnCreated  
        If (e.Column.ColumnType = "GridBoundColumn"AndAlso (Left(e.Column.UniqueName, 3) <> "TRA") Then 
            Dim bndcol As GridBoundColumn = DirectCast(e.Column, GridBoundColumn)  
            bndcol.[ReadOnly] = True 
          
        End If 
 
    End Sub 

Thank you very much for your time!
0
Shinu
Top achievements
Rank 1
answered on 21 May 2009, 05:37 AM
Hi Myriam,

Try the following code snippet to prevent the missing borders around the Grid cell.

VB:
 
  Protected Sub RadGrid2_PreRender(ByVal sender As ObjectByVal e As EventArgs) 
       For Each dataItem As GridDataItem In RadGrid2.Items 
          For Each col As GridColumn In RadGrid2.Columns 
              If dataItem(col.UniqueName).Text = String.Empty Then 
                   dataItem(col.UniqueName).Text += "&nbsp;" 
                    
                End If 
            Next 
       Next 
  End Sub 
 
 


Give a try with the following code snippet to reduce the size of the TextBox in edit mode.

VB:
 
 Protected Sub RadGrid2_ItemDataBound(ByVal sender As ObjectByVal e As GridItemEventArgs) 
     If (TypeOf e.Item Is GridEditFormItem) AndAlso (e.Item.IsInEditMode) Then 
         Dim editForm As GridEditFormItem = DirectCast(e.Item, GridEditFormItem) 
         Dim txtbx As TextBox = DirectCast(editForm("Year").Controls(0), TextBox) 
         txtbx.Width = Unit.Pixel(50) 
     End If 
 End Sub 


Shinu



Tags
Grid
Asked by
Myriam
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 1
Myriam
Top achievements
Rank 1
Share this question
or