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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T12:52:05+00:00 2026-06-08T12:52:05+00:00

How can I set the text in a button to bold depending if it

  • 0

How can I set the text in a button to bold depending if it has information in a datagridview.

Below is a sample project – create a windows application and put this code in.

What I want to do is if a field has information in it I want to make only that cell button font bold.

e.g. Based on the datatable in the code below

Row 1                    David                     Notes this row bold text in button

Row 2                    Sam                       Notes this row not

Row 3                    Christoff                 Notes this row not

Row 4                    Janet                     Notes this row bold text in button

Row 5                    Melanie                   Notes this row not

Code:

private void Form1_Load(object sender, EventArgs e) {
    DataTable table = GetTable();

    DataGridViewColumn col = new DataGridViewTextBoxColumn();
    col.HeaderText = "Dosage";
    col.Width = 80;
    int colIndex = dataGridView1.Columns.Add(col);

    DataGridViewColumn col2 = new DataGridViewTextBoxColumn();
    col2.HeaderText = "Drug";
    col2.Width = 75;
    colIndex = dataGridView1.Columns.Add(col2);

    DataGridViewColumn col3 = new DataGridViewTextBoxColumn();
    col3.HeaderText = "Patient";
    col3.Width = 75;
    colIndex = dataGridView1.Columns.Add(col3);

    DataGridViewColumn col4 = new DataGridViewTextBoxColumn();
    col4.HeaderText = "Date";
    col4.Width = 40;
    colIndex = dataGridView1.Columns.Add(col4);

    DataGridViewButtonColumn buttonCol = new DataGridViewButtonColumn();
    buttonCol.Name = "btnNotes";
    buttonCol.HeaderText = "Notes";
    buttonCol.Text = "Notes";
    buttonCol.Width = 80;
    buttonCol.UseColumnTextForButtonValue = true;
    buttonCol.DefaultCellStyle.Font = new Font("Arial", 12, FontStyle.Bold);
    dataGridView1.Columns.Add(buttonCol);

    // Add items to the grid
    int i = 0;

    foreach(DataRow rows in table.Rows) {
        dataGridView1.Rows.Add();
        dataGridView1[1, i].Value = rows[0].ToString();
        dataGridView1[1, i].Value = rows[1].ToString();
        dataGridView1[2, i].Value = rows[2].ToString();
        dataGridView1[3, i].Value = rows[3].ToString();

        if (rows[3].ToString().Trim().Length != 0) {

            //Because there are notes in this field, I would like to set this button text only to bold
        }


        i++;
    }

}

static DataTable GetTable() {
    DataTable table = new DataTable();
    table.Columns.Add("Dosage", typeof(int));
    table.Columns.Add("Drug", typeof(string));
    table.Columns.Add("Patient", typeof(string));
    table.Columns.Add("BlaBlaBla", typeof(string));

    table.Rows.Add(25, "Indocin", "David", "Notes in here");
    table.Rows.Add(50, "Enebrel", "Sam", "");
    table.Rows.Add(10, "Hydralazine", "Christoff", "");
    table.Rows.Add(21, "Combivent", "Janet", "Notes in here");
    table.Rows.Add(100, "Dilantin", "Melanie", "");

    return table;    
}
  • 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-08T12:52:07+00:00Added an answer on June 8, 2026 at 12:52 pm

    Hope that this will help you. I created a timer that updates the buttons styles.

            DataGridViewButtonColumn buttonCol = new DataGridViewButtonColumn();
            public Form1()
            {
                InitializeComponent();
    
                DataGridViewColumn col = new DataGridViewTextBoxColumn();
                col.HeaderText = "Dosage";
                col.Width = 80;
                int colIndex = dataGridView1.Columns.Add(col);
    
                DataGridViewColumn col2 = new DataGridViewTextBoxColumn();
                col2.HeaderText = "Drug";
                col2.Width = 75;
                colIndex = dataGridView1.Columns.Add(col2);
    
                DataGridViewColumn col3 = new DataGridViewTextBoxColumn();
                col3.HeaderText = "Patient";
                col3.Width = 75;
                colIndex = dataGridView1.Columns.Add(col3);
    
                DataGridViewColumn col4 = new DataGridViewTextBoxColumn();
                col4.HeaderText = "Date";
                col4.Width = 40;
                colIndex = dataGridView1.Columns.Add(col4);
    
    
                buttonCol.Name = "btnNotes";
                buttonCol.HeaderText = "Notes";
                buttonCol.Text = "Notes";
                buttonCol.Width = 80;
                buttonCol.UseColumnTextForButtonValue = true;
                buttonCol.DefaultCellStyle.Font = new Font("Arial", 12);
                dataGridView1.Columns.Add(buttonCol);
    
                timer1.Start();
                timer1.Tick += new EventHandler(timer1_Tick);
    
    
            }
    
            void timer1_Tick(object sender, EventArgs e)
            {
                int i = 0;
                foreach (DataGridViewRow row in dataGridView1.Rows)
                {
                    if (row.Cells[0].Value == null || row.Cells[1].Value == null || row.Cells[2].Value == null || row.Cells[3].Value == null)
                    {
                        dataGridView1.Rows[i].Cells[4].Style.Font = new Font(dataGridView1.Font, FontStyle.Regular);
                    }
                    else
                    {
                        dataGridView1.Rows[i].Cells[4].Style.Font = new Font(dataGridView1.Font, FontStyle.Bold);
                    }
                    i++;
                }
            }
    
    
    
            static DataTable GetTable()
            {
            DataTable table = new DataTable();
            table.Columns.Add("Dosage", typeof(int));
            table.Columns.Add("Drug", typeof(string));
            table.Columns.Add("Patient", typeof(string));
            table.Columns.Add("BlaBlaBla", typeof(string));
    
            table.Rows.Add(25, "Indocin", "David", "Notes in here");
            table.Rows.Add(50, "Enebrel", "Sam", "");
            table.Rows.Add(10, "Hydralazine", "Christoff", "");
            table.Rows.Add(21, "Combivent", "Janet", "Notes in here");
            table.Rows.Add(100, "Dilantin", "Melanie", "");
    
            return table;
            }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I do get that we easily can set the Close button text to a
How can I set the font/bold/italic/underline whatever of some text in a JEditorPane? I
How can I set default button after text is entered into a text box.
I have a problem I can't set the text of a button during a
Hilfe how can i set the text-style
Attempting to set up an automated texting service for customers, where people can text
I have a simple login form that has 2 text fields and a button.
Can I set a label (text) in popup menu (gtk.Menu) but without hovering effect,
Users can set the background-color of a button through a textbox that accept RGB
I have a basic text editor that can style documents (bold, underline, italicize, underline,

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.