web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Finance | Project Operations, Human Resources, ...
Suggested Answer

Changing colors does not work using a Dynamics GP winform under C#

(0) ShareShare
ReportReport
Posted on by 75,848 Moderator

I took this code from another C# application that changes the color of a row in a datagridview based on a value in one of the columns. The problem is when this code is used in a winform created as a Dynamics GP winform the color does not change. Is there anyway to get a row color to change based on a value inside a datagridview under a Dynamics GP winform?

            foreach (DataGridViewRow row in dgvTransferPOs.Rows)
                if (Convert.ToInt16(row.Cells[4].Value) == 1)
                {
                    row.DefaultCellStyle.BackColor = Color.Red;
                    row.DefaultCellStyle.ForeColor = Color.White;
                }
                else
                {
                    row.DefaultCellStyle.BackColor = Color.Yellow;
                    row.DefaultCellStyle.ForeColor = Color.Black;
                }

Categories:
I have the same question (0)
  • Andrea Melroe Profile Picture
    3,437 on at

    Hi Richard,

    While this is not something we’d be able to assist with, I know that there are some products/tools out there already that have the functionality you’re looking for. Here’s a link to an older forum post that talks about the color schemes for specific fields/rows/etc.

    https://www.gpug.com/communities/community-home/digestviewer/viewthread?GroupId=247&MID=27848&tab=digestviewer&CommunityKey=4754a624-39c5-4458-8105-02b65a7e929e

    There may be others in the community with other suggestions for you as well.

    I hope this helps!

    Thank you for using Microsoft Dynamics Communities,

    Andrea Melroe

    Sr. Technical Advisor

    Microsoft Dynamics GP

     

  • Richard Wheeler Profile Picture
    75,848 Moderator on at

    Andrea, i did get this to work. What is going on here is I wanted all closed PO's to be highlighted in red.

            private void dgvTransferPOs_DataBindingComplete(object sender, DataGridViewBindingCompleteEventArgs e)
            {
                var grid = sender as DataGridView;
                if (Equals(grid, dgvTransferPOs))
                {
                    // Using a well defined column
                    foreach (var row in grid.Rows.Cast<DataGridViewRow>())
                    {
                        // IsClosed is not visible, but we can still access the value
                        if (Convert.ToBoolean(row.Cells[5].Value))
                        {
                            row.DefaultCellStyle.BackColor = Color.Red;
                        }
                    }
                }
                else
                {
                    // Using a well defined type
                    foreach (var row in grid.Rows.Cast<DataGridViewRow>())
                    {
                        // IsWorking is not visible, but we can still access the value
                        if ((row.DataBoundItem as PODOC).IsClosed)
                        {
                            row.DefaultCellStyle.BackColor = Color.Red;
                        }
                        //else
                        //{
                        //    row.DefaultCellStyle.BackColor = Color.White;
                        //}
                    }
                }
            }

  • Suggested answer
    Beat Bucher  GP Geek  GPUG All Star Profile Picture
    28,058 Moderator on at

    Richard

    You may be able to achieve this the Developer module of the GPPT (GP PowerTools), even re-use some of the code above. Check it out with David Musgrave!

  • Richard Wheeler Profile Picture
    75,848 Moderator on at

    In case anybody wants this, this is what works. This is for a datagridview inside a GP Dynamics winform project.

           private void dgvTransferPOs_DataBindingComplete(object sender, DataGridViewBindingCompleteEventArgs e)

           {

               var grid = sender as DataGridView;

               if (Equals(grid, dgvTransferPOs))

               {

                   // Using a well defined column

                   foreach (var row in grid.Rows.Cast<DataGridViewRow>())

                   {

                       // IsClosed is not visible, but we can still access the value

                       if (Convert.ToBoolean(row.Cells[5].Value))

                       {

                           row.DefaultCellStyle.BackColor = Color.Red;

                       }

                   }

               }

               else

               {

                   // Using a well defined type

                   foreach (var row in grid.Rows.Cast<DataGridViewRow>())

                   {

                       // IsWorking is not visible, but we can still access the value

                       if ((row.DataBoundItem as PODOC).IsClosed)

                       {

                           row.DefaultCellStyle.BackColor = Color.Red;

                       }

                       //else

                       //{

                       //    row.DefaultCellStyle.BackColor = Color.White;

                       //}

                   }

               }

           }

  • Andrea Melroe Profile Picture
    3,437 on at

    Richard,

    I'm glad you were able to get that working, and that you've shared it here for others as well! I'm sure this will be beneficial for someone down the road!

    Thank you for using Microsoft Dynamics Communities,

    Andrea Melroe

    Sr. Technical Advisor

    Microsoft Dynamics GP

  • Richard Wheeler Profile Picture
    75,848 Moderator on at

    Andrea, it is great having you and your team contributing to this forum. It is very much appreciated having your expertise in here.

  • Andrea Melroe Profile Picture
    3,437 on at

    Hi Richard,

    That's so nice to hear, and we are happy to contribute!!

    Andrea Melroe

    Sr. Technical Advisor

    Microsoft Dynamics GP

  • Patrici2a Profile Picture
    5 on at

    I wanted to change the font size of page header in run time but it was not workable My Lowes Life.

  • Richard Wheeler Profile Picture
    75,848 Moderator on at

    Yes, I discovered that as well. There appear to be certain property of the form that cannot be changed. Perhaps Andrea might have some suggestions?

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > Finance | Project Operations, Human Resources, AX, GP, SL

#1
Martin Dráb Profile Picture

Martin Dráb 664 Most Valuable Professional

#2
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 522 Super User 2025 Season 2

#3
Sohaib Cheema Profile Picture

Sohaib Cheema 303 User Group Leader

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans