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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 10, 20262026-05-10T22:02:57+00:00 2026-05-10T22:02:57+00:00

I am binding a List to a DataGridView. One property of the SomeObject class

  • 0

I am binding a List to a DataGridView. One property of the SomeObject class will be a status code (ex. Red, Yellow, Green). Can I ‘bind’ the status to the background color of a cell easily? How about binding to a tooltip also?

  • 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. 2026-05-10T22:02:58+00:00Added an answer on May 10, 2026 at 10:02 pm

    You can write a handler for the DataGridView’s CellFormatting event to customise the background colour. Here’s a worked example (you’ll need to have dragged a DataGridView onto the default Form then double-clicked on the CellFormatting event to create a handler):

    using System.Drawing; using System.Windows.Forms;  namespace WindowsFormsApplication1 {     public partial class Form1 : Form     {         private BindingSource _source = new BindingSource();          public Form1()         {             InitializeComponent();              _source.Add(new MyData(Status.Amber, 'Item A'));             _source.Add(new MyData(Status.Red, 'Item B'));             _source.Add(new MyData(Status.Green, 'Item C'));             _source.Add(new MyData(Status.Green, 'Item D'));              dataGridView1.DataSource = _source;             dataGridView1.Columns[0].Visible = false;         }          private void dataGridView1_CellFormatting(object sender, DataGridViewCellFormattingEventArgs e)         {             if (e.ColumnIndex == 1)             {                 DataGridView dgv = sender as DataGridView;                 MyData data = dgv.Rows[e.RowIndex].DataBoundItem as MyData;                  switch (data.Status)                 {                     case Status.Green:                         e.CellStyle.BackColor = Color.Green;                         break;                     case Status.Amber:                         e.CellStyle.BackColor = Color.Orange;                         break;                     case Status.Red:                         e.CellStyle.BackColor = Color.Red;                         break;                 }             }         }     }      public class MyData     {         public Status Status { get; set; }         public string Text { get; set; }          public MyData(Status status, string text)         {             Status = status;             Text = text;         }     }      public enum Status     {         Green,         Amber,         Red     } } 

    The objects here just have a Status and Text for simplicity. I create a BindingSource for an example set of these objects, then use that as the data source for the DataGridView. By default, the grid automatically generates columns when you bind, so there’s no need to do that manually. I also hide the first column, which is bound to the Status value, as we’re going to colour the Text cells instead.

    To actually do the painting, we respond to the CellFormatting event. We get a reference to the DataGridView by casting sender, then use the RowIndex property of the DataGridViewCellFormattingEventArgs object to get at the data item iteself (each Row has a DataBoundItem property that conveniently gives us this). As DataBoundItem is an object type, we need to cast it to our specific type, then we can actually get to the Status property itself…phew!

    I haven’t had any experience with tooltip programming, but I would have thought that you should respond to the MouseHover event, then work on discovering which row is being pointed at to start with.

    I hope this helps.

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

Sidebar

Related Questions

Binding a List collection to a datagrid. How can you limit what properties will
I am binding a datagridview to a list of objects. One of its columns
Can anyone explain why I can rebind list but not +? (binding [list vector]
I have something like this: <ListBox ItemsSource={Binding List}> <ListBox.ItemContainerStyle> <Style TargetType=ListBoxItem> <Setter Property=HorizontalContentAlignment Value=Stretch></Setter>
Is there a better way of binding a list of base class to a
Im adding objects to a datagridview ( only one kind) through a list ej.
I have a BindingList<T> which is bound to a datagridview. One property in my
I have a List that I want to bind to a DataGridView in a
I am binding a list of objects to a DataGridView like the following var
I have a DataGridView populated with a BindingList . This list gets saved 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.