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

Column text alignment issue.

11 Answers 1708 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Trump
Top achievements
Rank 1
Trump asked on 13 Jul 2018, 12:56 AM

I have two columns in the GridView. I want one column's text(including header) is on the left, the other column is on the right.

<telerik:GridViewDataColumn  Header="Content" DataMemberBinding="{Binding Content}"  TextAlignment="Left" HeaderTextAlignmemt="Left" />
    
   <telerik:GridViewDataColumn  Header="Date" DataMemberBinding="{Binding Date}"  TextAlignment="Right" HeaderTextAlignmemt="Right" />

But it is not working, two columns are always aligned to the left. Then I used Visual Tree to check the properties. For the GridViewCell.

PART_CellBorder [Border]
   Background_Over [Border]
   Background_Selected[Border] etc

The default HorizontalAlignment is Stretch. I am not sure how to set the styles for the alignment.

Thanks.

11 Answers, 1 is accepted

Sort by
0
Trump
Top achievements
Rank 1
answered on 15 Jul 2018, 10:39 AM
One more sentence. Maybe the two columns have different width. So all columns shift to the left and appearing everything to the left. If I set the width = *  in GridViewDataColumn then the column width become almost infinity(very large width). Not sure why. 
0
Dinko | Tech Support Engineer
Telerik team
answered on 17 Jul 2018, 09:48 AM
Hi Trump,

What you can use for your scenario in order to pin the columns to the left/right is to use the LeftFrozenColumnCount/RightFrozenColumnCount property of the RadGridView. These properties are further described in the Frozen Columns help article in our documentation. In your case, check the following code snippet.
<telerik:RadGridView ItemsSource="{Binding Data}" AutoGenerateColumns="False" LeftFrozenColumnCount="1" RightFrozenColumnCount="1" >
    <telerik:RadGridView.Columns>
        <telerik:GridViewDataColumn DataMemberBinding="{Binding Content}"  TextAlignment="Left" HeaderTextAlignment="Left" />
        <telerik:GridViewDataColumn DataMemberBinding="{Binding Date}" TextAlignment="Right" HeaderTextAlignment="Right"/>
    </telerik:RadGridView.Columns>
</telerik:RadGridView>

Hope this functionality will work for your scenario.

Regards,
Dinko
Progress Telerik
Want to extend the target reach of your WPF applications, leveraging iOS, Android, and UWP? Try UI for Xamarin, a suite of polished and feature-rich components for the Xamarin framework, which allow you to write beautiful native mobile apps using a single shared C# codebase.
0
Trump
Top achievements
Rank 1
answered on 17 Jul 2018, 01:32 PM

I can't find it in RadGridView. It is in GridViewDataControl

My version is 2016

0
Dinko | Tech Support Engineer
Telerik team
answered on 19 Jul 2018, 01:55 PM
Hello Trump,

The LeftFrozenColumnCount and RightFrozenColumnCount properties of the RadGridView control are introduced with the R1 2018 version of our controls. I recommend you to download the latest version of our controls so you can take advantage of the latest features, bug fixes, and new controls.

Regards,
Dinko
Progress Telerik
Want to extend the target reach of your WPF applications, leveraging iOS, Android, and UWP? Try UI for Xamarin, a suite of polished and feature-rich components for the Xamarin framework, which allow you to write beautiful native mobile apps using a single shared C# codebase.
0
Trump
Top achievements
Rank 1
answered on 20 Jul 2018, 01:45 AM
Thanks for your suggestion. However out company doesn't have the plan to upgrade the library. I hope that there is an alternative solution. Again, we are using  telerik 2016 Q3.
0
Dilyan Traykov
Telerik team
answered on 23 Jul 2018, 03:36 PM
Hello Trump,

I've attached a small sample project where setting the TextAlignment and HeaderTextAlignment of the columns to Left and Right accordingly and setting the width of those columns to * seems to result in the desired layout at my end.

Could you please have a look and let me know whether this is indeed the case? If it is, please specify how this setup differs from the one you have at your end. If not, please specify your exact requirements so that I can further assist you.

I look forward to your reply.

Regards,
Dilyan Traykov
Progress Telerik
Want to extend the target reach of your WPF applications, leveraging iOS, Android, and UWP? Try UI for Xamarin, a suite of polished and feature-rich components for the Xamarin framework, which allow you to write beautiful native mobile apps using a single shared C# codebase.
0
Trump
Top achievements
Rank 1
answered on 24 Jul 2018, 12:13 AM

My case is similar with this.

Say we have the main view 

<ScrollViewer Grid.Row="5" VerticalScrollBarVisibility="Auto" HorizontalScrollBarVisibility="Auto">
        <ContentControl Grid.Row="5" Background="Transparent"  Focusable="False" Margin="0,5,0,0"
                            Content="{Binding CurrentSection}" ContentTemplateSelector="{StaticResource templateSelector}/>
</ScrollViewer>

The RadGridView is inside in the another view CurrentSection. If I set the Width = * for the two columns, then the width becomes very big(infinity). So it is not alignment issue, perhaps something else. Maybe Virtualization issue. I saw that there is a tip and trick.

I have spent several days on it and no clue.

Thanks. 

0
Trump
Top achievements
Rank 1
answered on 24 Jul 2018, 02:39 AM

And more in the View  CurrentSection, the Grid code likes.

<Grid>
   <Grid.RowDefinitions>
       <RowDefinition Height="auto" />
       <RowDefinition Height="*" />
   </Grid.RowDefinitions>
        <Somecontrol Grid.Row="0" />
        <telerik:RadGridView Grid.Row="0"
                             Style="{StaticResource MyStyle}"
                             RowStyle="{StaticResource SomeRowStyle}"
                             CanUserDeleteRows="False"
                             IsReadOnly="True" 
                             AutoGenerateColumns="False"
                             ShowGroupPanel="False"
                             IsFilteringAllowed="False"
                             CanUserReorderColumns="False"
                             RowIndicatorVisibility ="Collapsed"
                             EnableRowVirtualization="True"
                             EnableColumnVirtualization="True"
                             FrozenColumnCount="2"
                             SelectionUnit="FullRow"
                             SelectionMode="Extended"
                             AlternationCount="2"
                             AlternateRowBackground="LightSteelBlue">
                             <telerik:RadGridView.Columns>
                              <telerik:GridViewDataColumn DataMemberBinding="{Binding FirstName}" Header="First Name" HeaderCellStyle="{StaticResource GridViewHeaderCellStyle}" TextAlignment="Left" HeaderTextAligntment="Left" CellStyle="{StaticResource SomeCellStyle}" Width="*"/>
                              <telerik:GridViewDataColumn DataMemberBinding="{Binding LastName}" Header="Last Name" HeaderCellStyle="{StaticResource GridViewHeaderCellStyle}" TextAlignment="Right" HeaderTextAligntment="Right" CellStyle="{StaticResource SomeCellStyle}" Width="*"/>
    </telerik:RadGridView.Columns>
        </telerik:RadGridView>
</Grid>
0
Trump
Top achievements
Rank 1
answered on 24 Jul 2018, 02:42 AM

Sorry for some edit error,should remove the following lines.

 FrozenColumnCount="2"
                             SelectionUnit="FullRow"
                             SelectionMode="Extended"

0
Trump
Top achievements
Rank 1
answered on 24 Jul 2018, 10:58 PM

Resolved it. The case is actually similar with this.

The problem you see is because as the Datagrid is inside a ScrollViewer, it has virtually infinite space to expand,so it can't calculate widths.

<RadGridView AutoGenerateColumns="False" ColumnWidth="*"
Width="{Binding RelativeSource={RelativeSource FindAncestor,
AncestorType={x:Type ScrollViewer}}, Path=ViewportWidth}">

 

 

0
Dilyan Traykov
Telerik team
answered on 25 Jul 2018, 02:32 PM
Hello Trump,

Indeed, the result you described is expected when using a ScrollViewer. In fact, our Tips and Tricks article suggests not to place the control in such containers as apart from the issue you've come across, the control's virtualization mechanism turns off which results in poor performance.

Nonetheless, I'm glad to hear that you have resolved your issue. If you require any further assistance, please let me know.

Regards,
Dilyan Traykov
Progress Telerik
Want to extend the target reach of your WPF applications, leveraging iOS, Android, and UWP? Try UI for Xamarin, a suite of polished and feature-rich components for the Xamarin framework, which allow you to write beautiful native mobile apps using a single shared C# codebase.
Tags
GridView
Asked by
Trump
Top achievements
Rank 1
Answers by
Trump
Top achievements
Rank 1
Dinko | Tech Support Engineer
Telerik team
Dilyan Traykov
Telerik team
Share this question
or