Windows Vista Forums
Vista Forums Home Join Vista Forums Windows 7 Forum Vista Tutorials Tags
Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks.

Go Back   Vista Forums > Misc Newsgroups > Avalon

Vista - Simplest way to right-align GridViewColumn

 
 
Old 05-04-2006   #1 (permalink)
Sam Jost


 
 

Simplest way to right-align GridViewColumn

I've got a ListView, containing some numbers (currency and others), and
would like to be able to right-align the columns with numbers.

Since I can't find any tag on GridViewColumn to change the alignment,
whats the easiest way to achieve this?

Thanks,
Sam


My System SpecsSystem Spec
Old 05-04-2006   #2 (permalink)
Drew Marsh


 
 

Re: Simplest way to right-align GridViewColumn

Sam Jost wrote:

> I've got a ListView, containing some numbers (currency and others),
> and would like to be able to right-align the columns with numbers.
>
> Since I can't find any tag on GridViewColumn to change the alignment,
> whats the easiest way to achieve this?


I believe you'll need to define a CellTemplate for the column. In the template
just put a TextBlock and set it's TextAlignment to TextAlignment.Right. That
would look something like this:

<GridViewColumn ...>
<GridViewColumn.CellTempate>
<DataTemplate>
<TextBlock Text="{Binding Path=???}" TextAlignment="Right" />
</DataTemplate>
</GridViewColumn.CellTemplate>
</GridViewColumn>

HTH,
Drew
___________________________________
Drew Marsh
Chief Software Architect
Mimeo.com, Inc. - http://www.mimeo.com
Microsoft C# / WPF MVP
Weblog - http://blog.hackedbrain.com/


My System SpecsSystem Spec
Old 05-05-2006   #3 (permalink)
Sam Jost


 
 

Re: Simplest way to right-align GridViewColumn

Drew,

I had to change it a bit to make it work, but it does the trick. In the
end for me it looks like:

<ListView.Resources>
<DataTemplate x:Key="MyTemplate">
<TextBlock HorizontalAlignment="Right" Block.TextAlignment="Right"
Text="{Binding Path=MyData}"/>
</DataTemplate>
</ListView.Resources>
[...]
<GridViewColumn Width="80" Header="my data"
CellTemplate="{StaticResource MyTemplate}"/>

Thanks for the hint!
Sam

Drew Marsh schrieb:

> Sam Jost wrote:
>
> > I've got a ListView, containing some numbers (currency and others),
> > and would like to be able to right-align the columns with numbers.
> >
> > Since I can't find any tag on GridViewColumn to change the alignment,
> > whats the easiest way to achieve this?

>
> I believe you'll need to define a CellTemplate for the column. In the template
> just put a TextBlock and set it's TextAlignment to TextAlignment.Right. That
> would look something like this:
>
> <GridViewColumn ...>
> <GridViewColumn.CellTempate>
> <DataTemplate>
> <TextBlock Text="{Binding Path=???}" TextAlignment="Right" />
> </DataTemplate>
> </GridViewColumn.CellTemplate>
> </GridViewColumn>
>
> HTH,
> Drew
> ___________________________________
> Drew Marsh
> Chief Software Architect
> Mimeo.com, Inc. - http://www.mimeo.com
> Microsoft C# / WPF MVP
> Weblog - http://blog.hackedbrain.com/


My System SpecsSystem Spec
 

Thread Tools


Similar Threads
Thread Forum
How to Align Desktop items in VISTA??? Vista General
Simplest (Vista-compatible) macro-maker ??? Vista General
auto align icons horizontally Vista General


Vista Forums is an independent web site and has not been authorized,
sponsored, or otherwise approved by Microsoft Corporation.
"Windows Vista", the Start Orb, and related materials are trademarks of Microsoft Corp.
© Designer Media Ltd

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46