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

Grid Detail Table Column Visibility

3 Answers 232 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Darrin
Top achievements
Rank 1
Darrin asked on 03 Apr 2013, 04:34 PM
Hi,

I have a RadGrid with a nested GridTableView (detail table). In my detail table I've specified a RadComboBox as one of the columns like this:

<telerik:ComboBox ID="tcbCompanyType" runat="server" DataTextField="Text" DataValueField="Value"
    EmptyMessage="Company type" MarkFirstMatch="True" AutoPostBack="True"
    CausesValidation="false" onselectedindexchanged="tcbCompanyType_SelectedIndexChanged" />


As expected, on changing the selection, the appropriate method is called; but I need this method to show/hide other columns in the same detail table - my other columns are all of type <telerik:GridBoundColumn>. The columns to be shown/hidden all have unique names defined for them but no IDs.

Thanks for looking :)

3 Answers, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 2
answered on 04 Apr 2013, 06:25 AM
Hi,

Try the following code.
C#:
protected void RadComboBox1_SelectedIndexChanged(object sender, RadComboBoxSelectedIndexChangedEventArgs e)
   {
       RadComboBox combo = (RadComboBox)sender;
       foreach (GridDataItem item in grid.MasterTableView.Items)
       {
           if (item.HasChildItems)
           {
               foreach (GridTableView innerDetailView in item.ChildItem.NestedTableViews)
               {
                 innerDetailView.GetColumn("Uniquename").Visible=false;
 
               }
           }
       }
       
   }

Thanks,
Shinu.
0
Darrin
Top achievements
Rank 1
answered on 04 Apr 2013, 09:28 AM
Hi,

Thanks for the fast reply and apologies for not wording my question correctly - it's the edit form fields I need to hide so that, for example, I have an object consisting of ten fields, only three of which are visible. Only the three visible fields are shown in the grid of course but when I click on edit and the edit form is displayed, I see all ten fields. One of the fields is a RadCombo and on selection of certain items I then want to control the visibility of the controls in the same edit form as the RadCombo. I'd also like to be able to perform validation on these fields if possible.

Incidentally, an easier way to set the visibility of the column in the grid is as follows (I'm assuming I only have one detail table):

myGrid.MasterTableView.DetailTables[0].GetColumn("Uniquename").Visible = false;


Note that I'm able to reference it by its ID - I didn't have to do the following cast:

RadComboBox combo = (RadComboBox) sender;


Thanks :)
0
Eyup
Telerik team
answered on 08 Apr 2013, 10:19 AM
Hi Darrin,

I have already replied to your support ticket, however, I will copy the reply here, so it would be useful to other developers who face similar issues, too:

You can make avail of the ReadOnly property of GridColumns:
<telerik:GridDateTimeColumn ... ReadOnly="true">

Alternatively, you can access the generated controls and execute your custom logic:
   - First, you will need to access the Parent TableCell which holds the control and disable its Visible property:
( Section Accessing controls in edit/insert mode )
http://www.telerik.com/help/aspnet-ajax/grid-accessing-cells-and-rows.html

    - And then you can do that only on item inserting or on item editing:
http://www.telerik.com/help/aspnet-ajax/grid-distinguish-edit-insert-mode-on-itemcreated-itemdatabound.html

Hope this helps.

All the best,
Eyup
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now.
Tags
Grid
Asked by
Darrin
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
Darrin
Top achievements
Rank 1
Eyup
Telerik team
Share this question
or