0
votes

I am trying to display a Telerik RadGrid in my project. I have a problem with changing the column width. The data source of my grid is a list of objects. When I add filters to the grid, the columns' width is fixed and I cannot change it / resize it.

P.S. I want to solve this programmatically(in vb code)

my vb code:

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
    If Not IsPostBack Then
      setColumnsOnGrid(Of object)(lst, RadGrid1, ArrayNameFilds:={"column1", "column2", "column3 ", "etc."})
    End If
End Sub


Private Sub setColumnsOnGrid(Of T)(ByVal lst As List(Of T), ByVal grdName As RadGrid, ByVal ArrayNameFilds As Array)
    Dim nameFiled As String
    grdName.DataSource = lst
    grdName.AllowMultiRowSelection = True
    grdName.MasterTableView.AutoGenerateColumns = False

    Dim boundColumn As GridBoundColumn

    For i As Integer = 0 To ArrayNameFilds.Length - 1
        nameFiled = ArrayNameFilds(i).ToString()
        boundColumn = New GridBoundColumn()
        grdName.MasterTableView.Columns.Add(boundColumn)
        boundColumn.DataField = nameFiled
        boundColumn.HeaderText = nameFiled
     Next
End Sub

my aspx:

 <telerik:RadGrid ID="grd_test" runat="server" AllowFilteringByColumn="True" AllowPaging="True" AllowSorting="True" CellSpacing="0" GridLines="None">
    <ClientSettings>
        <Scrolling AllowScroll="True" UseStaticHeaders="True" />
    </ClientSettings>
</telerik:RadGrid>
1

1 Answers

0
votes

I found the answer on telerik forums:

grdName.MasterTableView.Columns(i).HeaderStyle.Width = System.Web.UI.WebControls.Unit.Pixel(50)
grdName.MasterTableView.Columns(i).FilterControlWidth = System.Web.UI.WebControls.Unit.Pixel(50)

you can also use the Percentage:

System.Web.UI.WebControls.Unit.Percentage