Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6932317
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T11:41:27+00:00 2026-05-27T11:41:27+00:00

How can I get a DataGridTextColumn to display a ‘-‘ (hyphen) instead of 0

  • 0

How can I get a DataGridTextColumn to display a ‘-‘ (hyphen) instead of 0.

Here is how the data grid is currently setup:

<Grid>
  <DataGrid x:Name="EmployeeHours"
            AutoGenerateColumns="False"
            ItemsSource="{Binding EmployeeHoursLastWeek}"
            Width="Auto">
    <DataGrid.Columns>
      <DataGridTextColumn Header="PerceptionistID"
                          Binding="{Binding PerceptionistID}"
                          Width="100" />
      <DataGridTextColumn Header="Week Of"
                          Binding="{Binding WeekOf, StringFormat={}{0:MM/dd/yyyy}}"
                          Width="75" />
      <DataGridTextColumn Header="Regular Hours"
                          Binding="{Binding WorkHours}"
                          Width="100" />
      <DataGridTextColumn Header="PTO Hours"
                          Binding="{Binding PTOHours}"
                          Width="100" />
      <DataGridTextColumn Header="Holiday Hours"
                          Binding="{Binding HolidayHours}"
                          Width="100" />
    </DataGrid.Columns>
  </DataGrid>
</Grid>

PTOHours and HolidayHours are typically 0 and it would make it easier to identify cells with a value other than 0 if any cell with 0 displayed a ‘-‘ instead.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T11:41:27+00:00Added an answer on May 27, 2026 at 11:41 am

    you can use a value converter for it

    <Grid>
      <Grid.Resources>
        <local:HoursToMinusConverter x:Key="HoursToMinusConverter" />
      </Grid.Resources>
    
      <DataGrid x:Name="EmployeeHours"
                AutoGenerateColumns="False"
                ItemsSource="{Binding EmployeeHoursLastWeek}"
                Width="Auto">
        <DataGrid.Columns>
          <DataGridTextColumn Header="PerceptionistID"
                              Binding="{Binding PerceptionistID}"
                              Width="100" />
          <DataGridTextColumn Header="Week Of"
                              Binding="{Binding WeekOf, StringFormat={}{0:MM/dd/yyyy}}"
                              Width="75" />
          <DataGridTextColumn Header="Regular Hours"
                              Binding="{Binding WorkHours}"
                              Width="100" />
          <DataGridTextColumn Header="PTO Hours"
                              Binding="{Binding PTOHours, Converter={StaticResource HoursToMinusConverter}}"
                              Width="100" />
          <DataGridTextColumn Header="Holiday Hours"
                              Binding="{Binding HolidayHours, Converter={StaticResource HoursToMinusConverter}}"
                              Width="100" />
        </DataGrid.Columns>
      </DataGrid>
    </Grid>
    

    here is the converter

    public class HoursToMinusConverter : IValueConverter
    {
      public object Convert(object value, Type targetType, object parameter, CultureInfo culture) {
        if (value is int) {
          return (int)value > 0 ? value.ToString() : "-";
        }
        return string.Empty;
      }
    
      public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) {
        if (value is string) {
          int intValue;
          if (!int.TryParse((string)value, out intValue)) {
            intValue = 0;
          }
          return intValue;
        }
        return 0;
      }
    }
    

    hope this helps

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a datagrid like this: <dg:DataGrid Name=dg AutoGenerateColumns=False CanUserDeleteRows=True> <dg:DataGrid.Columns> <dg:DataGridTextColumn Header=Product Code
Can get work the attribute destroy-method. First, even if I type non-existing method name
I have a data grid that looks like this <tk:DataGrid ItemsSource={Binding Parents} AutoGenerateColumns=False> <tk:DataGrid.Columns>
How can i stop a WPF DataGrid form automatic display an element binded to
How can I get the DataGrid for a given DataGridColumn . I've created an
I have a datagrid displaying the contents of a custom data type. <DataGrid Name=TestGrid
You can get the fully qualified class name of a Python object like this
Can get all triples with value null in specific field? All people with date_of_birth
I can get easily see what projects and dlls a single project references from
I can get both System.Net.Mail and System.Web.Mail to work with GMail, but I can't

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.