Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>My best guess is that some part of your code is just really slow.</p> <p>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 <em>impression</em> that the event fires continuously. It does not, however.</p> <p>Here are some pointers to improve performance:</p> <ul> <li>You are constructing a new <code>DivaDs</code> every time the event fires <ul> <li>Instead, consider reusing the same instance of the class as a member variable</li> <li>What happens in the constructor?</li> </ul></li> <li>Take a closer look at the <code>GetBackColor</code> method or <code>ColorTranslator.FromHtml</code> and see if any modifications can be made to improve performance.</li> </ul> <p><strong>Update</strong></p> <p>It appears you are querying the database for each cell in the grid. This is a really bad idea.</p> <p>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.</p> <pre><code>// member variable private Dictionary&lt;byte, Color&gt; 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 =&gt; r.Field&lt;byte&gt;("ActionTypeID"), r =&gt; ColorTranslator.FromHtml(r.Field&lt;string&gt;("ColorCode"))); } } </code></pre> <p>Call the <code>BuildActionTypeColorDictionary</code> method before setting the data source of the grid. In the <code>RowStyle</code> or <code>CustomDrawCell</code> events, use the new dictionary member to determine the background color. See the following modified version of your <code>RowStyle</code> code:</p> <pre><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&lt;byte&gt;("ActionImage"); // look up color in the dictionary: e.Appearance.BackColor = actionTypeColorDict[actionTypeID]; } catch (Exception ex) { XtraMessageBox.Show(ex.Message); } } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload