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

Hierarchical grid - columns in inner-grid refusing to resize

3 Answers 57 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Patrick
Top achievements
Rank 1
Patrick asked on 29 Oct 2012, 06:32 PM
The subject pretty much says all.  I can't seem to find any way to get the columns in the inner-grid of a two-level hierarchical RadGrid to resize.  Below is the code I'm attempting:

ASPX:
<telerik:RadGrid ID="XLSView" runat="server" AutoGenerateColumns="True" AllowMultiRowSelection="true" Width="600px">
    <MasterTableView Width="100%">
        <DetailTables>
            <telerik:GridTableView Width="100%">
                <Columns>           
                    <telerik:GridTemplateColumn UniqueName="chkDup" HeaderText="Select">
                        <ItemTemplate>
                            <asp:CheckBox ID="chkDup" runat="server">
                            </asp:CheckBox>
                        </ItemTemplate>
                        <HeaderStyle Width="200px" />
                    </telerik:GridTemplateColumn>
                </Columns>
            </telerik:GridTableView>
        </DetailTables>
    </MasterTableView>
    <ClientSettings>
        <Scrolling AllowScroll="true" />
    </ClientSettings>
</telerik:RadGrid>

VB:
Protected Sub XLSView_DetailTableDataBind(sender As Object, e As Telerik.Web.UI.GridDetailTableDataBindEventArgs) Handles XLSView.DetailTableDataBind
 
...
            Dim test As DataTable = New DataTable()
            test.Columns.Add("FileID")
...
            For Each dupFile As FILE In dupFiles
                Dim dr As DataRow = test.NewRow()
                dr("FileID") = dupFile.FILEID
...
            Next
            e.DetailTableView.DataSource = test
 
------------------------------------
 
    Protected Sub XLSView_ColumnCreated(sender As Object, e As Telerik.Web.UI.GridColumnCreatedEventArgs) Handles XLSView.ColumnCreated
        If e.Column.UniqueName = "Description" Then
            Dim boundColumn As GridBoundColumn = CType(e.Column, GridBoundColumn)
            boundColumn.HeaderText = "DescriptionA"
            boundColumn.ItemStyle.Width = 600
            boundColumn.HeaderStyle.Width = 600
            boundColumn.FooterStyle.Width = 600
            boundColumn.FilterControlWidth = 600
        End If
    End Sub

I get a good hierarchial grid, with the only exception being that the column of checkboxes that's in the ASPX will not widen and the numerous column resize attempts in the ColumnCreated function(which DOES fire correctly; the HeaderText property does change to "DescriptionA") also will not widen.  Can anybody please tell me what I'm doing wrong?

Thank you for any help you may have in advance.

Patrick

3 Answers, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 2
answered on 30 Oct 2012, 08:44 AM
Hi,

I suppose you want to change the width of the CheckBox column in the DetailTable. Please make sure that you have set 'Name' property of the GridTableView.

ASPX:
<telerik:GridTableView Width="100%" Name="Detail">
. . .

C#:
protected void RadGrid1_ItemDataBound(object sender, GridItemEventArgs e)
{
    if (e.Item is GridHeaderItem)
    {
        GridHeaderItem item = (GridHeaderItem)e.Item;
        if (e.Item.OwnerTableView.Name == "Detail")
        {
            LiteralControl Literal = (LiteralControl)item["chkDup"].Controls[0];
            Literal.Text = "your text";
        }
    }
    if (e.Item is GridDataItem)
    {
        if (e.Item.OwnerTableView.Name == "Detail")
        {
            GridDataItem data = (GridDataItem)e.Item;
            TableCell check = (TableCell)data["chkDup"];
            check.Width = 600;
        }
    }
}

Thanks,
Shinu.
0
Patrick
Top achievements
Rank 1
answered on 30 Oct 2012, 02:40 PM
Hi Shinu,
Thank you for your reply.  I have now placed names GridTableView as prescribed.

Unfortunately, your solution only partially works.  I WAS able to change the header text successfully as in here: (VB)
If TypeOf e.Item Is GridHeaderItem Then
    Dim item As GridHeaderItem = CType(e.Item, GridHeaderItem)
    If e.Item.OwnerTableView.Name = "detail" Then
        Dim literal1 As LiteralControl = CType(item("chkDup").Controls(0), LiteralControl)
        literal1.Text = "your text"
        Dim data As GridTableHeaderCell = CType(e.Item.Cells(2), GridTableHeaderCell)
        'data.Width = 600
        'data.BorderWidth = 600
    End If
End If

The header does indeed change it's text to "your text".  However, the cell does NOT resize as in here: (VB)
If TypeOf e.Item Is GridDataItem Then
    If e.Item.OwnerTableView.Name = "detail" Then
        Dim data As GridDataItem = CType(e.Item, GridDataItem)
        Dim check As TableCell = CType(data("chkDup"), TableCell)
        check.Width = 600
    End If
End If

However, the width is filled in the style attribute of the TD tag when I look at the page source in Firefox.  

You may have noticed two commented lines in the first block.  I figured I could try to widen the correct column in the header row, which would in turn widen the entire column.  The first commented line does not work and even doesn't fill in the style attribute in the TH tag if you retrieve the page source in FireFox.  However, the second line DOES fill in the style attribute in the TH tag and produces the "desired effects".  I place that in quotes because it's obviously not what I'm looking for (it makes the header row REALLY tall and wide), but at least it's a start...

I appreciate any further assistance you may have.

Thanks again,
Patrick
0
Patrick
Top achievements
Rank 1
answered on 30 Oct 2012, 06:27 PM
OK, I think I figured out my problem.  I think the issue was that I required UseStaticHeaders="true".  This allowed resizing of the columns.  I did then have the issue of a lack of scroll bars when a detail grid came into being.  I was able to get around that by making the last column of the main grid really wide.  It's a bit hokey, but it should accomplish what I need to do.

Let me know if there may be a better way to approach the issues I'm having.

Thanks again,
Patrick
Tags
Grid
Asked by
Patrick
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
Patrick
Top achievements
Rank 1
Share this question
or