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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T11:44:52+00:00 2026-05-27T11:44:52+00:00

I am probably missing something realy simple, but i cannot get it to work

  • 0

I am probably missing something realy simple, but i cannot get it to work properly.

I am filling a Datagridview. Then i have a Databindingcomplete event to go over the rows and give them colors and fonts depending on certain criteria.

This is done with the following code:

foreach (DataGridViewRow r in dataGridView1.Rows)
            {
                if ((r.Cells["referrer"].Value.ToString().Contains("DBS")) & (r.Cells["priority"].Value.ToString().Equals("1")))
                {
                    r.DefaultCellStyle = DBS;
                    r.DefaultCellStyle.Font = new Font("Arial", 9, FontStyle.Bold);
                }

                else if ((r.Cells["referrer"].Value.ToString().Contains("DBS")) & (r.Cells["priority"].Value.ToString().Equals("0")))
                {
                    r.DefaultCellStyle = DBS;
                    r.DefaultCellStyle.Font = new Font("Arial", 9, FontStyle.Regular);
                }

                else if ((r.Cells["referrer"].Value.ToString().Contains("agenda")) & (r.Cells["priority"].Value.ToString().Equals("0")))
                {
                    r.DefaultCellStyle = agenda;
                    r.DefaultCellStyle.Font = new Font("Arial", 9, FontStyle.Regular);
                }

                else if ((r.Cells["referrer"].Value.ToString().Contains("agenda")) & (r.Cells["priority"].Value.ToString().Equals("1")))
                {
                    r.DefaultCellStyle = agenda;
                    r.DefaultCellStyle.Font = new Font("Arial", 9, FontStyle.Bold);
                }

                else if ((r.Cells["referrer"].Value.ToString().Contains("sms")) & (r.Cells["priority"].Value.ToString().Equals("1")))
                {
                    r.DefaultCellStyle = sms;
                    r.DefaultCellStyle.Font = new Font("Arial", 9, FontStyle.Bold);
                }

                else if ((r.Cells["referrer"].Value.ToString().Contains("sms")) & (r.Cells["priority"].Value.ToString().Equals("0")))
                {
                   r.DefaultCellStyle = sms;
                   r.DefaultCellStyle.Font = new Font("Arial", 9, FontStyle.Regular);
                }

                else if ((r.Cells["referrer"].Value.ToString().Contains("remoteLogin")) & (r.Cells["priority"].Value.ToString().Equals("1")))
                {
                    r.DefaultCellStyle = remoteLogin;
                    r.DefaultCellStyle.Font = new Font("Arial", 9, FontStyle.Bold);
                }

                else if ((r.Cells["referrer"].Value.ToString().Contains("remoteLogin")) & (r.Cells["priority"].Value.ToString().Equals("0")))
                {
                    r.DefaultCellStyle = remoteLogin;
                    r.DefaultCellStyle.Font = new Font("Arial", 9, FontStyle.Regular);
                }
            }

Now this is working. the first line of the DefaultCellStyle is for colors of the row, then the second line is the font.

Everything works ok, colors are good, bold works, regular works, except one thing.

If i have 2 rows:

A) agenda with priority 1

B) agenda with priority 0

It will go past the first one, adjusts the color good, makes it bold. But then the second one will also be bold. If i change them so the first one is priority 0, both will be regular.

I can have all types of events, all will be bold or regular, all have the correct color settings. But when i have a second of of the same type (DBS, agenda, remoteLogin or sms) the second and so on will have the same font as the first one.

So this batch will do the following:

[DBS – 1] –> Correct color, and bold (correct)

[agenda – 0] –> Correct color and regular (correct)

[sms – 1] –> Correct color, and bold (correct)

[remoteLogin – 0] –> Correct color and regular (correct)

[DBS – 0] –> Correct color and Bold (Incorrect font!)

[agenda – 1] –> Correct color and regular (Incorrect font!)

I hope i make sense explaining. Maybe i’m not seeing something or i want something stupid. Maybe someone can tell me what is wrong.
the code might not be the best now, since i have made many adjustments trying to make it work.

Edit:
I just noticed that it does do the foreach correct, but when it encounters the a second one of the same type, it will change the font of the one before also. Maybe i can work around it.

Thx in advance!
Mike

  • 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-27T11:44:52+00:00Added an answer on May 27, 2026 at 11:44 am

    I figured it out.

    I create the DefaultCellStyle with the colors for each item (DBS, agenda, etc.) Then i change the Font of that DefaultCellStyle to Bold or regular. When the foreach loop encounters a second row of the same type. It loads the same DefaultCellStyle, lets say “DBS” as the other one. Inside of that i adjust the Fontstyle. Because i now update the Fontstyle inside the “DBS” item, all rows with the “DBS” DefaultCellStyle get affected. I think the only way around this is to make a diffrent DefaultCellStyle for each option in the list.

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

Sidebar

Related Questions

I'm probably missing something very basic but I cannot figure out why I get
I'm probably missing something simple here, but I can't find the answer elsewhere. I
I know I'm probably missing something easy, but I have a foreach loop and
Probably I'm just missing something obvious, but I can't get the image in my
Okay, I'm probably missing something really simple here, but I've been at this for
Probably simple question and I'm just missing something, but I'm stuck out of ideas.
I'm probably missing something really obvious but I have an xml file that I
Probably missing something completely obvious here, but here goes. I'm starting out with Spring
I'm probably missing something very obvious here. I have files with the extension .st
I'm probably missing something obvious here but here's what I'm trying to do. From

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.