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

Autogenerated columns seem to be cached between different datasources

5 Answers 90 Views
Grid
This is a migrated thread and some comments may be shown as answers.
EmpowerIT
Top achievements
Rank 2
EmpowerIT asked on 05 Feb 2008, 05:58 AM
Hi,
I had a rad grid which gets bound a totally different datasource based on certain events. I have enabled autogenerated columns and this works all fine. I have some logic on the ColumnCreated event to set the visible flag on the column based on some criteria. This is all working fine.

However, i have noticed that if there are columns with the same names, in two different datasources, the autogenerated column property gets cached!

E.g I have DataSource1 and DataSource2. Both contain a column called UserId. When displaying DataSource1 i want to hide that column. I do that by setting the visible property to false. When I switch to datasource2, i do not want to hide this column, but it still hides it (even though the visible property is set to true)! If i switch to a different datasource (i.e datasource3) which does not contain a column of the same name, and then switch back to datasource2, it will display that column....
What I need is some way of letting the RadGrid know that it needs to regenerated all the autogenerated columns, even though they may have the same name.
Or if possible, a way to add a custom prefix to the UniqueName of the autogenerated columns

Below is the code I use to set the visible property:
 void RadGrid1_ColumnCreated(object sender, GridColumnCreatedEventArgs e) 
    { 
        if (myAdminTree != null && myAdminTree.SelectedNode != null
        { 
            string uniqName = e.Column.UniqueName; 
            
            if (myAdminTree.CurrentDataKeyNames.Contains(uniqName)) 
            { 
                e.Column.Visible = false
            } 
        } 
    } 


Thanks,

5 Answers, 1 is accepted

Sort by
0
Yavor
Telerik team
answered on 06 Feb 2008, 03:00 PM
Hello,

If the columns have the same name, they will remain invisible, as per the code sample included.
You can further differentiate between the columns, by checking the e.OwnerTableView property, which would give you access to the mastertable, in which the columns are nested, and thus have a chance to toggle their visibility on/off, based on the mastertable differences.
Additionally, the following article contains additional information pertaining to altering the control structure dynamically.
I hope this information helps.

Sincerely yours,
Yavor
the Telerik team

Instantly find answers to your questions at the new Telerik Support Center
0
EmpowerIT
Top achievements
Rank 2
answered on 06 Feb 2008, 10:26 PM
Sorry, I think you have not understood what I meant ... let me try to elaborate.

I have 3 totally different datasources: e.g

DataSource1 has columns: UserID UserName Password

DataSource2 has columns: RecId,RecName,UserId

DataSource3 has columns: DiffId, DiffName,DiffField

The grid is initially bound to datasource1. The grid is a simple one table grid, no hierarchy or nesting. Based on some logic, the autogenerated userId column is set to be invisible for this case.

The user intereacts with the page, and now causes the grid to bind to a different datasource, DataSource2.

Based on the criteria, all the columns should remain visible. When i step through the debugger in Visual Studio all the columns have their visible property set to true. But when the grid is rendered on the page, the UserId column(which is hidden in datasource1) does not display.

If the user now interacts with the page again and causes the grid to bind to datasource3 (which does not have a column called UserID), and then interacts once more to cause the grid to bind back to datasource2, the UserID field becomes visible

The settings on the RadGrid is to AutoGenerateColumns.

From what I can see, it seems that the RadGrid is making an assumption that autogenerated columns of the same name do not need to be regenerated, even though the datasource has changed. If the datasource does not contain a definition for a particular column it is removed, hence the reason it works correctly if i switch between datasources which do not set different values of the visible property for columns of the same name, or if the column names between the datasources do not overlap

Thanks again,
Fayez
0
Yavor
Telerik team
answered on 11 Feb 2008, 12:30 PM
Hi,

You can try explicitly toggling on the visibility of the column.
This is demonstrated in the sample project attched to this message.
Let me know how it goes.

Greetings,
Yavor
the Telerik team

Instantly find answers to your questions at the new Telerik Support Center
0
EmpowerIT
Top achievements
Rank 2
answered on 11 Feb 2008, 10:55 PM
I think I found my problem. I was trying to toggle the visibility in the ColumnCreated event, but i think this was too early and it was being overwritten. I now just hook into the RadGrid DataBound event, and then iterate through all the autogenerated columns and set the properties appropriately. It works as its supposed to now.
Is there somewhere where we can see the RadGrid lifecycle, in terms of its events and when it is being rebound etc

Thanks
0
Accepted
Sebastian
Telerik team
answered on 12 Feb 2008, 09:20 AM
Hello EmpowerIT,

To familiarize with the event lifecycle and sequence of RadGrid Prometheus review the Controls -> RadGrid -> The control lifecycle chapter from the online documentation:

http://www.telerik.com/help/radcontrols/prometheus/

Best,
Stephen
the Telerik team

Instantly find answers to your questions at the new Telerik Support Center
Tags
Grid
Asked by
EmpowerIT
Top achievements
Rank 2
Answers by
Yavor
Telerik team
EmpowerIT
Top achievements
Rank 2
Sebastian
Telerik team
Share this question
or