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

  • SEARCH
  • Home
  • 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 9314409
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 19, 20262026-06-19T02:07:35+00:00 2026-06-19T02:07:35+00:00

i have a DataGridTextColumn that accepts numbers from a database table called Numbers. If

  • 0

i have a DataGridTextColumn that accepts numbers from a database table called Numbers. If the number in cell is positive than i want the next DataGridTextColumn to have the word “Positive” inside. I tried with IConverter Styles but still dont know how to do it right.I hope someone can help me.

This is my code so far:

<DataGrid Grid.Row="0" Grid.Column="1" AutoGenerateColumns="False" IsReadOnly="false" CanUserAddRows="True" Margin="5,5,10,5" ItemsSource="{Binding ElementName=Numbers}">

        <DataGrid.Columns>
            <DataGridTextColumn Binding="{Binding Num}" Header="Number" FontSize="16"/>

            <DataGridTextColumn Header="Positive/Negative" FontSize="16">

                <DataGridTextColumn.ElementStyle>
                    <Style TargetType="{x:Type TextBlock}">
                        <Setter Property="Text" Value="{Binding Amount, Converter={StaticResource PositiveNegativeConverter}}"/>
                    </Style>
                </DataGridTextColumn.ElementStyle>
            </DataGridTextColumn>
    </DataGrid>

I also have this inside Resources:

    <local:PositiveNegativeConverter x:Key="PositiveNegativeConverter"/>
</UserControl.Resources>      

My Converter looks like this:

class PositiveNegativeConverter : IValueConverter
{
  public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
    {
        bool revert = (parameter as string).StartsWith("-");

        string stringValue = value as string;
        string compareValue = parameter as string;

        if (revert)
        {
            return "Negative";
        }
        else
            return "Positive";
    }
    public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
    {
        throw new NotSupportedException();
    }
}
  • 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-06-19T02:07:36+00:00Added an answer on June 19, 2026 at 2:07 am

    You do not have to add a style for that, just add the converter to the Binding in the DataGridTextColumn.

    Something like this:

    <DataGridTextColumn Binding="{Binding Num, Converter={StaticResource PositiveNegativeConverter}}" Header="Number" FontSize="16"/>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm using .NET 3.5 I have a DataGridTextColumn that I want to turn the
i have a datagrid that load the data from my database. in my datagrid,
I have a WPF DataGrid that I want to be able to Update, Insert
I Have the following class that I want to bind to a grid but
i am porting my application from windows forms to WPF. I have found that
I have a DataGrid and it has a DataGridTextColumn that has items which I
I have an object called TestData that contains two properties, a string and an
I have the following class that I want to bind it's dictionary's value to
I currently have a Combo box that has data that is bind from a
I have just started to create a user control realising that I want a

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.