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

How to apply horizontalAlignment dynamically for column.dataType in an Autogenerated GridView?

7 Answers 50 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Oscar
Top achievements
Rank 1
Oscar asked on 28 Mar 2011, 04:31 PM
Hi,
It seems that autogenerated GridView sets all its columns to horizontalAlignment=Left. I would like to set the horizontalAlignment cells depending on its dataType column. HorizontalAlignment should be:
    
  • Left for strings
  • Right for numeric 
  • Center for boolean dataType
.
How can I accomplish this?

7 Answers, 1 is accepted

Sort by
0
Pavel Pavlov
Telerik team
answered on 28 Mar 2011, 04:59 PM
Hello Oscar,

You can gain control over  the autogenerated columns in the AutoGeneratingColumn event of  RadGridView.
Inside the event handler, you may alter the settings of each autogenerated column.

Let me know in case you need additional assistance on this .

Best wishes,
Pavel Pavlov
the Telerik team
0
Oscar
Top achievements
Rank 1
answered on 29 Mar 2011, 05:29 PM
Thank you, Pavel, but... I can't find the horizontalAligment property for the cell of the e.column.
0
Vlad
Telerik team
answered on 30 Mar 2011, 06:42 AM
Hi,

 You can use GridViewColumn TextAlignment property to achieve your goal. 

Kind regards,
Vlad
the Telerik team
0
Oscar
Top achievements
Rank 1
answered on 30 Mar 2011, 09:12 AM
TextAlignment does not work for boolean dataType. The checkBox always appears aligned to the left for boolean dataType column.
0
Vanya Pavlova
Telerik team
answered on 30 Mar 2011, 02:25 PM
Hi,

 
For such columns you may also assign cell style with TargetType GridViewCell, where you may set the HorizontalContentAligment to an appropriate value and the checkboxes will be aligned correspondingly.


Best wishes,
Vanya Pavlova
the Telerik team
0
Daniel
Top achievements
Rank 1
answered on 01 Oct 2012, 08:33 PM
How do i achieve this for all the grids in the project, as i do not want to write the auto generating event for every grid.

One way is to achieve this when autogeneratincolumn=true is to extend radgridview with control templates. can you provide me the control template of radgridview.

Thanks
0
Vlad
Telerik team
answered on 02 Oct 2012, 05:31 AM
Hello,

 You may want to create attached behavior and reuse it for all grids in your application. You can even bind your columns from a view-model similar to various our demos. 

Regards,
Vlad
the Telerik team

Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

Tags
GridView
Asked by
Oscar
Top achievements
Rank 1
Answers by
Pavel Pavlov
Telerik team
Oscar
Top achievements
Rank 1
Vlad
Telerik team
Vanya Pavlova
Telerik team
Daniel
Top achievements
Rank 1
Share this question
or