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

[Solved] Errors When AutoGenerateColumns = False

1 Answer 131 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Jeremy Yoder
Top achievements
Rank 1
Jeremy Yoder asked on 22 Dec 2009, 05:21 PM

I had AutoGenerateColumns set to True, pointed my dataset to RadGrid1.DataSource, and everything worked fine. Now I set AutoGeneateColumns to False and manually add the columns. Here's my simplified code for test purposes...

    Protected Sub CreateColumns(ByVal ds As DataSet)  
        RadGrid1.Columns.Clear()  
        RadGrid1.AutoGenerateColumns = False 
        Dim dt As DataTable = ds.Tables(0)  
        For i As Integer = 0 To dt.Columns.Count - 1  
            AddColumn(dt.Columns(i).ColumnName)  
        Next 
    End Sub 
 
    Protected Sub AddColumn(ByVal strColumnName As String)  
        Dim col As New GridBoundColumn  
        col.DataField = strColumnName  
        col.HeaderText = strColumnName  
        RadGrid1.Columns.Add(col)  
    End Sub 

After doing this, if I click on the Header to sort the column, the grid does not sort, and all the HeaderText along the top disappears. Filtering also throws this error: "is neither a DataColumn nor a DataRelation for table DefaultView". Am I missing some setting? If it helps, here's my RadGrid...

        <telerik:RadGrid ID="RadGrid1" runat="server" AllowFilteringByColumn="True" AllowPaging="True" 
            AllowSorting="True" GridLines="None" AutoGenerateColumns="False">  
            <ClientSettings> 
                <Selecting AllowRowSelect="True" /> 
            </ClientSettings> 
        </telerik:RadGrid> 

1 Answer, 1 is accepted

Sort by
0
Schlurk
Top achievements
Rank 2
answered on 23 Dec 2009, 02:51 PM
I think you may need to define a bit more with the RadGrid than what you are currently doing. If you follow the example from this documentation article I think you can solve the issue you are running into.
Tags
Grid
Asked by
Jeremy Yoder
Top achievements
Rank 1
Answers by
Schlurk
Top achievements
Rank 2
Share this question
or