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

Hiding zeros in cells

5 Answers 35 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Sean Wright
Top achievements
Rank 1
Sean Wright asked on 19 May 2010, 03:26 PM
Hello,

In my GridView I have a column which shows numeric values. If the value is zero (0) I would like to replace that value with a dash ("-"). Is there a way to do that in the xaml using the DataFormatString method, or ResultFormatString method?

Thank you in advance.

5 Answers, 1 is accepted

Sort by
0
Pavel Pavlov
Telerik team
answered on 19 May 2010, 03:38 PM
Hi Sean Wright,

The easiest way to do that is to make a small IValueConverter and use it in the DataMemberBinding of the column.Within the Convert method  you may write th logic to return the "-" when the value is 0.

Let me know in case you need a sample on this.

Greetings,
Pavel Pavlov
the Telerik team

Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
0
Sean Wright
Top achievements
Rank 1
answered on 19 May 2010, 03:43 PM
Thank you, Pavel...

I would appreciate an example on how to do this, please.
0
Accepted
Pavel Pavlov
Telerik team
answered on 19 May 2010, 03:50 PM
Hello Sean Wright,

Actually we have this demonstrated in our QSF. Please have a look at this online example.
The "Discontinued" column uses an IValueConverter to display different content in the cell depending on the input value. Please click the <View Code> button to see the implementation of the IValueConverter.

For your case you will need to slightly alter  the Convert method so that when the value is 0 -> return "-" else return the value itself.

Regards,
Pavel Pavlov
the Telerik team

Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
0
Sean Wright
Top achievements
Rank 1
answered on 19 May 2010, 03:55 PM
Got it. Thank you very much for your quick reply, Pavel.
0
Sean Wright
Top achievements
Rank 1
answered on 19 May 2010, 06:41 PM
OK, what am I doing wrong? I can't get the xaml code in my Grid.Resources section to "see" the conversion class I wrote in the C# code-behind:

 

 

xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"

 

 

 

xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"

 

 

 

 

xmlns:d="http://schemas.microsoft.com/expression/blend/2008"

 

 

 

xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"

 

 

 

mc:Ignorable="d"

 

xmlns

 

 

:controls="clr-namespace:Telerik.Windows.Controls;assembly=Telerik.Windows.Controls.GridView"

 

 

 

xmlns:telerik="clr-namespace:Telerik.Windows.Data;assembly=Telerik.Windows.Data" x:Class="SES.UI.Silverlight.OnScreenReports.SES027ResultsScreen"

 

 

 

xmlns:telerikPresentation="http://schemas.telerik.com/2008/xaml/presentation"

 

 

 

xmlns:conversion="clr-namespace:SES.UI.Silverlight.OnScreenReports"

 

 

 

>

 

 

 

 

<Grid x:Name="LayoutRoot">

 

 

 

 

<Grid.Resources>

 

 

 

 

<conversion:ConvertZeroToDash x:Key="ZeroConverter"></conversion:ConvertZeroToDash>

 

 

 

 

</Grid.Resources>

 



Here is start of the C# code-behind for this screen:

 

 

public partial class SES027ResultsScreen : UserControl, IXWindowed<SES027ResultsScreen>{

 

 

 

public SES027ResultsScreen(){

 

InitializeComponent();

 

}


Thank you...
Tags
GridView
Asked by
Sean Wright
Top achievements
Rank 1
Answers by
Pavel Pavlov
Telerik team
Sean Wright
Top achievements
Rank 1
Share this question
or