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

Resize asp.net RadGrid columns

5 Answers 76 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Mark
Top achievements
Rank 1
Mark asked on 17 Feb 2017, 08:08 PM

I have created a RadGrid.  Here is the steps I used to create it and then remove all the rows (I just want the header - details why below)

I clear the rows in the datatable that I bind to the grid

I set the RadGrid datasource = to that blank datatable

I then bind

I also set the NoDetailRecordsText = "" and NoMasterRecordsText = ""

I have column headers that are dates (1/12 for example) and each day they change.  Those are in the middle of the columns.  All the other columns have named headers I know about (except the dates)

Column layout

Hardware Model 1/2  1/3  1/4 Col1 Col2 etc.

I need to set all the columns to a value (only way i know to set those date ones but code I have tried does not work) in ItemCreated event

For Each col As GridColumn In grdHeader.MasterTableView.Columns                 

     col.HeaderStyle.Width = "60"             'Never gets to this

Next

then go and set the rest of the column widths (this seems to work)

Dim gridCol As GridColumn             

gridCol = grdHeader.MasterTableView.GetColumn("Model")        

gridCol.HeaderStyle.Width = "140"

The reason I need to do this is we have scrolling RadGrids per group and I want to keep the header above the scrolling section as when it scrolls each header for each grid goes away and you have no clue what cols go with what data.

I hope this give enough to hopefully point me in the right direction.

I appreciate any help

5 Answers, 1 is accepted

Sort by
0
Mark
Top achievements
Rank 1
answered on 21 Feb 2017, 03:32 PM
So where is the support????  Frustrating that is has been 5 days and nothing.  
0
Eyup
Telerik team
answered on 22 Feb 2017, 06:20 AM
Hi Mark,

Generally, you can enable the UseStaticHeaders property of the grid to achieve this requirement:
http://demos.telerik.com/aspnet-ajax/grid/examples/functionality/scrolling/scrolling/defaultcs.aspx

And you can control the visibility of the header when there are no records using the following property:
<MasterTableView ... ShowHeadersWhenNoRecords="true">

I hope this will prove helpful. If you have different requirements or further instructions, please elaborate on your specific scenario and send us sample screenshots or video demonstrating the desired behavior.

Regards,
Eyup
Telerik by Progress
Try our brand new, jQuery-free Angular 2 components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
0
Mark
Top achievements
Rank 1
answered on 22 Feb 2017, 12:53 PM

I have put these in the page_load:

grdHeader.MasterTableView.ShowHeadersWhenNoRecords = True

grdHeader.ClientSettings.Scrolling.UseStaticHeaders = True

This is where i am trying to resize the col widths:

Private Sub grdHeader_ItemCreated(sender As Object, e As GridItemEventArgs) Handles grdHeader.ItemCreated         Try             For intLcv As Integer = 2 To e.Item.Cells.Count - 1                 Select Case e.Item.Cells(intLcv).Text                     Case "Model"                         e.Item.Cells(intLcv).Width = "50" 'Unit.Pixel(80)                     Case "Hardware"                         e.Item.Cells(intLcv).Width = "50" 'Unit.Pixel(80)                     Case "LoHi"                         e.Item.Cells(intLcv).Width = "50" 'Unit.Pixel(80)                     Case "Schedule"                         e.Item.Cells(intLcv).Width = "50" 'Unit.Pixel(80)                     Case Else                         

            Next

      Catch ex As Exception     

      End Try

End Sub

They are not resizing.....  Thanks for the reply

0
Accepted
Eyup
Telerik team
answered on 27 Feb 2017, 12:39 PM
Hello Mark,

Try executing this logic in a later stage of the page life cycle, for example PreRender:
Protected Sub RadGrid1_PreRender(sender As Object, e As EventArgs)
    For Each column As GridColumn In RadGrid1.MasterTableView.RenderColumns
        If column.UniqueName = "ShipName" Then
            column.HeaderStyle.Width = 500
        End If
    Next
End Sub

This approach works as expected on my side.

Regards,
Eyup
Telerik by Progress
Try our brand new, jQuery-free Angular 2 components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
0
Mark
Top achievements
Rank 1
answered on 27 Feb 2017, 01:30 PM
Thank you that worked!
Tags
Grid
Asked by
Mark
Top achievements
Rank 1
Answers by
Mark
Top achievements
Rank 1
Eyup
Telerik team
Share this question
or