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 9186715
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T19:35:56+00:00 2026-06-17T19:35:56+00:00

I have a datagrid, whose itemssource is binded to the model by using MVVM.

  • 0

I have a datagrid, whose itemssource is binded to the model by using MVVM.
The data is returned by a stored procedure, for a particular row say for row with code “A”, I wish to display data only in certain columns, the rest of the columns should display empty string.
How can I create a converter for this?

  • 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-17T19:35:57+00:00Added an answer on June 17, 2026 at 7:35 pm

    There are couple of ways you can do that.
    The first and easy approach is to massage the data in the model itself so you have the proper data binding.
    The other approach is head on model. Here is how you do it, lets say you have class Product and it has Name and Color in it. If the Color is red then do not want to show the name. So my XAML would look like the following

        <sdk:DataGrid x:Name="grid" AutoGenerateColumns="False" HorizontalAlignment="Left" Height="300" VerticalAlignment="Top" 
                      Width="400">
            <sdk:DataGrid.Columns>
                <sdk:DataGridTextColumn Binding="{Binding Converter={StaticResource MyConverter}, ConverterParameter=Color}" />
                <sdk:DataGridTextColumn Binding="{Binding Converter={StaticResource MyConverter}, ConverterParameter=Name}" />
            </sdk:DataGrid.Columns>
        </sdk:DataGrid>
    

    My code behind is nothing but stright data binding

            var products = Product.GetProducts(200);
            grid.ItemsSource = products;
    

    My converter will have

    public class Converter:IValueConverter
    {

        public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            if (value != null)
            {
                Product p = value as Product;
                switch (parameter as string)
                {
                    case "Name":
                        if (p.Color == "Red")
                            return "";
                        else
                            return p.Name;
                    case "Color":
                        return p.Color;
                }
            }
            return null;
        }
    
        public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            throw new NotImplementedException();
        }
    }
    

    ** The trick in here is the binding, I am binding to the full row and pass the column name as the parameter.This way, even column is generating, value converter is called everytime and you can apply your logic to it.

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

Sidebar

Related Questions

Say I have a DataGrid with its ItemsSource binding to a data table(whose columns
I have a WinForms .NET datagrid whose data source is a List<cLineItem> called lines.
I have a DataGrid whose ItemsSource is bound to a changing Observable Collection. Inside
I have a datagrid whose itemsSource is bound to a multiconverter which uses a
I am using vb.net 2010. I have a datagridview whose data source is a
I have a stored procedure that handles sorting, filtering and paging (using Row_Number) and
I have a datagrid that displays items with two columns of text row data
I am Using Silverlght 4.I have a datagrid Header whose text=StudentDetailOfAplication.Since It Occupies more
I'm just beginning with Silverlight. I have a DataGrid whose ItemsSource is linked to
I have a data set whose elements are displayed as rows in a DataGrid.

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.