API Questions on Kentico API.
Version 6.x > API > Hide a column in UniGrid View modes: 
User avatar
Member
Member
Aon_Vlado - 8/22/2012 2:47:33 PM
   
Hide a column in UniGrid
I am trying to hide a column of UniGrid as needed in code:

Using following XML:

<?xml version="1.0" encoding="utf-8" ?>
<grid>
<columns>
<column source="##ALL##" externalsourcename="FileName" name="FileName " sort=" FileName " caption="Name" wrap="false" width="25%" />
<column source="FileDescription" externalsourcename="FileDescription" name="FileDescription" sort="FileDescription" caption="Description" wrap="true" width="75%" />
</columns>
</grid>


gridFiles.GridName = "~/CMSModules/MyModules/FilesDescr.xml";
gridFiles.NamedColumns["FileDescription"].Visible = false;


Unfortunately I cannot find out why the last row throws and error:

gridFiles.NamedColumns["FileDescription"]' threw an exception of type 'System.Collections.Generic.KeyNotFoundException'
base {System.SystemException}: {"The given key was not present in the dictionary."}

what could be wrong?

Is there a better way to hide some columns which are already set in XML?

Thanks,

Vlado

User avatar
Kentico Support
Kentico Support
kentico_janh - 8/23/2012 2:11:54 AM
   
RE:Hide a column in UniGrid
Hello,

You can set the Visible property directly in your XML definition:

<?xml version="1.0" encoding="utf-8" ?>
<grid>
<columns>
<column source="##ALL##" externalsourcename="FileName" name="FileName " sort=" FileName " caption="Name" wrap="false" width="25%" />
<column source="FileDescription" Visible="false" externalsourcename="FileDescription" name="FileDescription" sort="FileDescription" caption="Description" wrap="true" width="75%" />
</columns>
</grid>


Best regards,
Jan Hermann

User avatar
Member
Member
Aon_Vlado - 8/23/2012 7:05:56 AM
   
RE:Hide a column in UniGrid
Thank you, but this is not the solution I was looking for. I need to show/hide it in code. This should be controlled by web part property.

Vlado

User avatar
Kentico Developer
Kentico Developer
kentico_ivanat - 8/25/2012 4:40:24 PM
   
RE:Hide a column in UniGrid
Hi,

in this case you will need to move definition you the UniGrid form the xml file to the code behind as described for example here:
advanced uni grid

Each column is represented by its control so you can play with visibility.

Best regards,
Ivana Tomanickova

User avatar
Member
Member
Aon_Vlado - 8/25/2012 6:33:04 PM
   
RE:Hide a column in UniGrid
Very good artcile. This is what I was looking for.
Thank you.

User avatar
Member
Member
mmacarie - 3/12/2014 10:27:30 AM
   
RE:Hide a column in UniGrid
The problem is that in the xml configuration of the columns you should replace name with columnname.