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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T03:52:56+00:00 2026-05-16T03:52:56+00:00

I have 2 variable I would like to display in one cell of a

  • 0

I have 2 variable I would like to display in one cell of a DataGridView.

Icon stockIcon;
Int stockStatus;

I already looked at http://msdn.microsoft.com/en-us/library/7tas5c80.aspx But I think its way to complicated and don’t show how to display to variables in one cell.

I don’t need the ability to edit, only display the two variables.

Could someone provide me with a small example?

I work in C# 4.0 and its a System.Windows.Forms.DataGridView

  • 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-16T03:52:56+00:00Added an answer on May 16, 2026 at 3:52 am

    Here is my own solution. Just set the Column type to LagerStatusColumn and it gets the job done.

     public class LagerStatusColumn : DataGridViewColumn
    {
        public LagerStatusColumn()
        {
            CellTemplate =
                new LagerStatusCell();
            ReadOnly = true;
        }
    }
     public class LagerStatusCell : DataGridViewTextBoxCell
    {
        protected override void Paint(System.Drawing.Graphics graphics, System.Drawing.Rectangle clipBounds, System.Drawing.Rectangle cellBounds, int rowIndex, DataGridViewElementStates cellState, object value, object formattedValue, string errorText, DataGridViewCellStyle cellStyle, DataGridViewAdvancedBorderStyle advancedBorderStyle, DataGridViewPaintParts paintParts)
        {
            base.Paint(graphics, clipBounds, cellBounds, rowIndex, cellState, value, "", errorText, cellStyle,
                       advancedBorderStyle, paintParts);
    
            var cellValue = Convert.IsDBNull(value) ? 0 : Convert.ToDecimal(value);
    
            const int horizontaloffset = 2;
    
            var parent = (LagerStatusColumn)this.OwningColumn;
    
            var fnt = parent.InheritedStyle.Font;
    
            var icon = Properties.Resources.lager;
            if (cellValue == 0)
                icon = Properties.Resources.rest;
            else if (cellValue < 0)
                icon = Properties.Resources.question_white;
    
            const int vertoffset = 0;
            graphics.DrawIcon(icon, cellBounds.X + horizontaloffset,
                 cellBounds.Y + vertoffset);
    
            var cellText = formattedValue.ToString();
            var textSize =
                graphics.MeasureString(cellText, fnt);
    
            //  Calculate the correct color:
            var textColor = parent.InheritedStyle.ForeColor;
            if ((cellState &
                 DataGridViewElementStates.Selected) ==
                DataGridViewElementStates.Selected)
            {
                textColor = parent.InheritedStyle.
                    SelectionForeColor;
            }
    
            // Draw the text:
            using (var brush = new SolidBrush(textColor))
            {
                graphics.DrawString(cellText, fnt, brush,
                                    cellBounds.X + icon.Width + 2,
                                    cellBounds.Y + 0);
            }
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I would like to have a variable (or #define ) in C++ source that
I have a variable myvar = document.getElementById('myid').innerHTML that I would like to replace all
I have a variable which contains the value 1234567 . I would like it
I would like to have my script accepting variable arguments. How do I check
I would like to have a random number generated based of a variable called
I would like to have the $ (dollar sign) which indicates a php variable
I have this string stored in a variable: IN=bla@some.com;john@home.com Now I would like to
I have a dataset of environmental variables I would like to use for a
I have a file containing substituted variables ( #{...} ) and I would like
I want to have a string variable for a PHP class, which would be

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.