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

  • Home
  • SEARCH
  • 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 9229475
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T05:34:52+00:00 2026-06-18T05:34:52+00:00

I wrote a method which changes backcolor of the rows before painting gridview in

  • 0

I wrote a method which changes backcolor of the rows before painting gridview in devexpress. It works fine but I realized that my code begins slowing down. Then I’ve found that the event firing continuously. It never stops. How can I handle this? Is there any way to stop firing event manually after gridview painted or should I try to solve this problem with an another event or another method???

Here is my event:

private void gvStep_CustomDrawCell(object sender, DevExpress.XtraGrid.Views.Base.RowCellCustomDrawEventArgs e)
    {
        try
        {
            DataRowView drw = (DataRowView)gvStep.GetRow(e.RowHandle);
            byte actionTypeID = (byte)drw.Row["ActionType"];

            //string colorCode = (new DivaDs()).GetBackColor(actionTypeID);
            string colorCode = divaDs.GetBackColor(actionTypeID);
            Color backColor = ColorTranslator.FromHtml(colorCode);
            e.Appearance.BackColor = backColor;                
        }
        catch (Exception ex)
        {
            XtraMessageBox.Show(ex.Message);   
        }

    }

public string GetBackColor(byte actionTypeID)
    {
        string color = string.Empty;
        using (SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings[DivaSqlSiteConnString].ConnectionString))
        {
            using (SqlCommand cmd = new SqlCommand(@"Select BackColor from ActionTypes where ID = @actionTypeID"))
            {
                SqlParameter param = new SqlParameter("@actionTypeID", actionTypeID);

                cmd.Parameters.Add(param);
                cmd.Connection = conn;
                conn.Open();
                color = cmd.ExecuteScalar().ToString();
                conn.Close();
            }
        }
        return color;
    }
  • 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-18T05:34:53+00:00Added an answer on June 18, 2026 at 5:34 am

    My best guess is that some part of your code is just really slow.

    The event only fires for each visible cell in the grid. If you attempt to debug the event, focus will shift to the debugger, and when you return to the application the cells need to be redrawn, causing the event to fire again, thus giving the impression that the event fires continuously. It does not, however.

    Here are some pointers to improve performance:

    • You are constructing a new DivaDs every time the event fires
      • Instead, consider reusing the same instance of the class as a member variable
      • What happens in the constructor?
    • Take a closer look at the GetBackColor method or ColorTranslator.FromHtml and see if any modifications can be made to improve performance.

    Update

    It appears you are querying the database for each cell in the grid. This is a really bad idea.

    A simple solution would be to preload all ActionTypes and their background colors (or at least the subset of ActionTypes that is displayed in the grid) before setting the grid’s data source.

    // member variable
    private Dictionary<byte, Color> actionTypeColorDict;
    
    void BuildActionTypeColorDictionary()
    {
        string connectionString = ConfigurationManager
          .ConnectionStrings[DivaSqlSiteConnString].ConnectionString;
    
        using (SqlConnection conn = new SqlConnection(connectionString))
        using (SqlCommand cmd = conn.CreateCommand())
        using (SqlDataAdapter adapter = new SqlDataAdapter(cmd))
        {
           // load all action type IDs and corresponding background color:
           cmd.CommandText = @"SELECT ActionTypeID, BackColor FROM ActionTypes";       
           DataTable actionTypeTable = new DataTable();
           adapter.Fill(actionTypeTable);
    
           // build a dictionary consisting of action type IDs
           // and their corresponding colors
           actionTypeColorDict = actionTypeTable.AsEnumerable().ToDictionary(
               r => r.Field<byte>("ActionTypeID"),
               r => ColorTranslator.FromHtml(r.Field<string>("ColorCode")));
       }
    }
    

    Call the BuildActionTypeColorDictionary method before setting the data source of the grid. In the RowStyle or CustomDrawCell events, use the new dictionary member to determine the background color. See the following modified version of your RowStyle code:

    private void gvStep_RowStyle(object sender,DevExpress.XtraGrid.Views.Grid.RowStyleEventArgs e)
    {
        try
        {
            DataRow row = gvStep.GetDataRow(e.RowHandle);
            if (row == null)
                return;
    
            byte actionTypeID = row.Field<byte>("ActionImage");
    
            // look up color in the dictionary:
            e.Appearance.BackColor = actionTypeColorDict[actionTypeID];
        }
        catch (Exception ex)
        {
            XtraMessageBox.Show(ex.Message);
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following method which works fine: button21.FlatAppearance.BorderSize = 0; button21.FlatAppearance.MouseOverBackColor = System.Drawing.Color.Transparent;
Some time ago, I wrote some code to decide which method of updating mutable
I wrote a JavaScript class called MyClass in which I've defined a method closeThis
I wrote a method that extracts fields from an object like this: private static
I want to write a method which takes two pointers to ints and changes
I actually wrote a method which switches some UIViews. When I enter the method
I wrote a script which changes the class of div in li according to
I have a method which I wrote like this: void updateMyJaxb(final JAXBElement<?> jaxbElement) {
I wrote the class Link which has a method shortTolong() this should return the
So I have a method I wrote that will copy the selectedValue from one

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.