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

Master/Detail - Identify Columns

3 Answers 82 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Todd
Top achievements
Rank 1
Iron
Todd asked on 07 Jul 2011, 07:21 PM
I have a hierarchical grid with just a master table and a detail table.  I am allowing autocolumn creation when the datasource is bound.  As the columns are created I need to selectively hide and format some of them.  I do this in the ColumnCreated procedure using a GridBoundColumn variable to reference each column in turn.  The problem is that I can't find a way to identify whether a column is in the master table or the detail table to determine what to do with it.  If all column names were unique this wouldn't be an issue but some of them aren't and they need to be seen on either the master record or the detail record, but not both.

Thanks for any help you can give me.

3 Answers, 1 is accepted

Sort by
0
Accepted
Shinu
Top achievements
Rank 2
answered on 08 Jul 2011, 07:52 AM
Hello Todd,

Try the following code snippet in the ItemCommand event.
C#:
protected void RadGrid1_ItemCreated(object sender, GridItemEventArgs e)
   {
       if (e.Item.OwnerTableView.Name == "Detail")
       {
         GridTableView childGrid = (GridTableView)e.Item.OwnerTableView;
         childGrid.GetColumn("EmployeeID").Visible=false;
       }
       if (e.Item.OwnerTableView.Name == "Master")
       {
         GridTableView master = (GridTableView)e.Item.OwnerTableView;
         master.GetColumn("LastName").Visible = false;
       }
   }

Thanks,
Shinu.
0
Todd
Top achievements
Rank 1
Iron
answered on 08 Jul 2011, 12:44 PM
So in general where is the proper place to put code to hide/display/format columns?  Is it in the ItemCreated event or in the ColumnCreated event?
0
Mira
Telerik team
answered on 13 Jul 2011, 05:10 PM
Hello Todd,

The ColumnCreated event is fired after the creation of auto-generated columns only.
That is way I recommend you use the ItemCreated event as Shinu suggested.

I hope this helps.

Kind regards,
Mira
the Telerik team

Register for the Q2 2011 What's New Webinar Week. Mark your calendar for the week starting July 18th and book your seat for a walk through of all the exciting stuff we will ship with the new release!

Tags
Grid
Asked by
Todd
Top achievements
Rank 1
Iron
Answers by
Shinu
Top achievements
Rank 2
Todd
Top achievements
Rank 1
Iron
Mira
Telerik team
Share this question
or