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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T03:08:36+00:00 2026-06-09T03:08:36+00:00

I have an existing application with a new requirement to show an image in

  • 0

I have an existing application with a new requirement to show an image in a DataGridView cell to denote whether the record has a specific flag associated with it or not (not user editable, this comes from the DB).

If there is a flag, I show the corresponding image, and if there’s no flag, I want nothing to be shown in the column.

The DataGridView columns weren’t created in Visual Studio designer, or else this would easy. I could just set the NullValue property on the column. Instead the columns are created at runtime when all the data is loaded into a DataTable, and then a DataView is created from that DataTable, and then the DataGridView’s Datasource is set to the DataView.

I can’t completely rewrite this, or else I’d just define the columns in VS Designer instead of this ridiculous way of just letting the columns be defined from the DataTable.

My question is then, how can I make it so the column with the Images shows nothing when the underlying data table has a null?

Here’s some pseudo C# to demonstrate what I mean. Remember, I didn’t write it to use two DataTables like this; it was that way when I had it handed to me, and I don’t want to make drastic changes just to add a new column…

DataTable rawData = someMethodThatReturnsMyRawData();
DataTable data = new DataTable();
data.Columns.Add("Flags", typeof(Image));
data.Columns.Add("SomeOtherColumn");

foreach (DataRow rawDataRow in rawData.Rows)
{
    DataRow dataRow = data.NewRow();
    bool hasFlagType1 = false;
    bool hasFlagType2 = false;

    if (rawDataRow["FlagType1ID"] != DBNull.Value)
    {
        hasFlagType1 = true;
    }

    if (rawDataRow["FlagType2ID"] != DBNull.Value)
    {
        hasFlagType2 = true;
    }

    if (hasFlagType1 && hasFlagType2)
    {
        dataRow[0] = Properties.Resources.BothFlagsImage;
    }
    else if (hasFlagType1)
    {
        dataRow[0] = Properties.Resources.FlagType1Image;
    }
    else if (hasFlagType2)
    {
        dataRow[0] = Properties.Resources.FlagType2Image;
    }
    else
    {
        //If neither flag set, I don't want it to show anything,
        //but if I leave it as null, a little box with an X in it shows up
        //I could set it to some transparent GIF here, but that seems lame
    }

    dataRow[1] = rawDataRow["SomeOtherColumn"];

    data.Rows.Add(dataRow);        
}

DataView dv = new DataView(data, string.Empty, "SomeOtherColumn ASC", DataViewRowState.CurrentRows);

this.emptyDataGridViewFromDesigner.DataSource = dv;

// How can I modify the column "Flags" at this point to show nothing if the value is null?

EDIT: Here’s a screenshot so you can see what I mean by the little box with an X – those are all nulls…

DataGridView with Null Images

Also, it has to be .NET 3.5, so if there’s a solution in .NET 4.0 only, I’m out of luck.

  • 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-09T03:08:37+00:00Added an answer on June 9, 2026 at 3:08 am

    I figured this out…

    Have to cast the column as a DataGridViewImageColumn, then set the DefaultCellStyle.NullValue for that column to null. From my example above, you’d do it like this…

    ((DataGridViewImageColumn)this.emptyDataGridViewFromDesigner.Columns["Flags"]).DefaultCellStyle.NullValue = null;
    

    I guess I jumped the gun asking here, but hope this helps someone else sometime.

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

Sidebar

Related Questions

A new requirement has come into an existing application. Current, we have an organization
I have an existing application (with MySQL DB). I just got a new requirement
We have an existing application for which one of our DTO object has a
I'm new to Rails, but I have an existing Rails application for which I
I have existing Java application that is using Acegi for authentication/authorization. Our new web
I've started work recently at a new company and they have an existing application
I have an existing application that has the following entities in the database Customer
I have an existing application which does all of its logging against log4j. We
We have an existing application that relies heavily on stored procedures and untyped DataSets.
I have an existing application that imports data from a web site api into

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.