We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date

ConditionalFormats not working after grid reset

Hi,
I have strange problem where ConditionalFormats work at first but when need to refresh data ConditionalFormats collection gets blanked even though re-added.

I found some work arounds, like first setting the Datasource to a dummy select and a 5 second delay before the ApplyXmlSchema, 4 seconds or less and the bug is still there which is strange. The ConditionalFormats collection is emptied somewhere along the way, that's the main problem

Some kind of threaded thing going on I presume, I've also had to use Control.CheckForIllegalCrossThreadCalls = false.

Now I cannot find a work around when this refresh/reload data is on a background thread, the 5 sec delay/dummy select aren't helping.

So so why so much trouble with ConditionalFormats?

Here's some code for the non threaded work around, putting the same in new thread isn't working.

public void noedit()
{
  // style needed to be executed first as part of work around, was at bottom.
  this.gridGroupingControl1.TableModel.EnableLegacyStyle = false;
  this.gridGroupingControl1.GridVisualStyles = GridVisualStyles.Office2010Blue;
  this.gridGroupingControl1.GridOfficeScrollBars = OfficeScrollBars.Metro;

  gridGroupingControl1.TableDescriptor.AllowEdit = false;
  gridGroupingControl1.TableDescriptor.AllowNew = false;
  gridGroupingControl1.TableDescriptor.AllowRemove = false;
     
  if (gridGroupingControl1.TableDescriptor.ConditionalFormats.Count == 0)
  {
    GridConditionalFormatDescriptor format = new GridConditionalFormatDescriptor("specialColor1");
    format.Expression = "[Pickup Status] like 'NR'";
    format.Appearance.AnyRecordFieldCell.BackColor = Color.LightGray;
    gridGroupingControl1.TableDescriptor.ConditionalFormats.Add(format);

    format = new GridConditionalFormatDescriptor("specialColor2");
    format.Expression = "[Pickup Status] like 'AP'";
    format.Appearance.AnyRecordFieldCell.BackColor = Color.LightGreen;
    gridGroupingControl1.TableDescriptor.ConditionalFormats.Add(format);

    // ... many more
   
  }
  gridGroupingControl1.TableModel.CellModels["EllipsisText"] = new EllipsisCellModel(gridGroupingControl1.TableModel);
}
     
private void resetgrid(bool dogrp)
{

  try
  {
    this.Cursor = Cursors.WaitCursor;

    System.Data.SqlClient.SqlDataAdapter dataAdapter = null;   // work around 1
    DataSet _dataSet = null;
    dataAdapter = new System.Data.SqlClient.SqlDataAdapter("select top 1 * from workorders", this.sqlConnection1);
    _dataSet = new DataSet();
    dataAdapter.Fill(_dataSet);

    this.gridGroupingControl1.CancelEdit();
    this.gridGroupingControl1.ResetTableDescriptor();

    this.gridGroupingControl1.Engine.DataMember = "";
    this.gridGroupingControl1.Engine.DataSource = null;
    this.gridGroupingControl1.Engine.DataSource = _dataSet.Tables[0];
    this.gridGroupingControl1.EndUpdate(false);

    this.gridGroupingControl1.TableModel.Selections.Clear();
    this.gridGroupingControl1.ResetTableDescriptor();
    this.gridGroupingControl1.DataMember = "";
    ((DataTable)this.gridGroupingControl1.DataSource).Clear();
    this.gridGroupingControl1.DataSource = null;
    this.gridGroupingControl1.DataSource = this.dataSet191.WorkOrders;
    this.gridGroupingControl1.CancelEdit();
    this.sqlDataAdapter1.Fill(this.dataSet191);
   
    this.gridGroupingControl1.TableOptions.ListBoxSelectionMode = SelectionMode.MultiExtended;
    this.gridGroupingControl1.TableOptions.AllowSelection = GridSelectionFlags.Any;

    noedit();
  }
  catch (Exception ex)
  {
    this.Cursor = Cursors.Arrow;
    MessageBox.Show("resetgrid: " + ex.ToString());
  }
  finally
  {
    this.Cursor = Cursors.Arrow;
  }
 
}

private void reloadgrid()
{

  this.gridGroupingControl1.SuspendLayout();
  this.gridGroupingControl1.BeginUpdate();

  String pane = this.gridGroupingControl1.TableDescriptor.Name;
  System.IO.MemoryStream stream = new System.IO.MemoryStream();
  System.Xml.XmlTextWriter xw = new System.Xml.XmlTextWriter(stream, null);
  this.gridGroupingControl1.WriteXmlSchema(xw);
  stream.Position = 0;

  System.IO.MemoryStream stream2 = new System.IO.MemoryStream();
  System.Xml.XmlTextWriter xw2 = new System.Xml.XmlTextWriter(stream2, null);
  this.gridGroupingControl1.WriteXmlLookAndFeel(xw2);
  stream2.Position = 0;

  this.resetgrid();

  this.gridGroupingControl1.EndUpdate(true);  // placing here also work around
  this.gridGroupingControl1.ResumeLayout();

  Thread.Sleep(5000);  // work around 2

  Control.CheckForIllegalCrossThreadCalls = false;  // work around
  this.gridGroupingControl1.TableDescriptor.ConditionalFormats.Clear();
  noedit();

  System.Xml.XmlTextReader xr = new System.Xml.XmlTextReader(stream);
  System.Xml.XmlTextReader xr2 = new System.Xml.XmlTextReader(stream2);

  this.gridGroupingControl1.ApplyXmlSchema(xr);
  this.gridGroupingControl1.ApplyXmlLookAndFeel(xr2);

  this.gridGroupingControl1.TableOptions.ListBoxSelectionMode = SelectionMode.MultiExtended;
  this.gridGroupingControl1.TableOptions.AllowSelection = GridSelectionFlags.Any;
  this.gridGroupingControl1.TableDescriptor.Name = pane;
  xw.Close();
  xr.Close();
  xw2.Close();
  xr2.Close();

  Control.CheckForIllegalCrossThreadCalls = true;
}




16 Replies

SA Solai A L Syncfusion Team April 9, 2014 11:49 AM UTC

Hi Dave,

 

Thanks for using Syncfusion products.

 

We would like to let you know that the reported issue is not reproduced at our end. Moreover, by observing your code we found that the conditional formatting is applied only after serialization. Could you please let us know your requirement much briefly? So, it would be easy for us to provide you a prompt solution.

And for further clarification we have provided a sample(attached) implementing the same.Please let us know if you have any other concerns.

 

Thanks & Regards,

AL.Solai.

 


Attachment: ConditionalFormatting_547929dc.zip


DA Dave April 9, 2014 04:18 PM UTC

Hi,

Please send acc.mdb I'll try to reproduce in your example. I think it has to do with the speed at which the serialization/conditional formats occur, no file dialog in between, also possibly the larger amount of data from mssql. Sure seems like a thread race on my end.

About "conditional formatting is applied only after serialization", conditional formats are already there from form load at that point, putting extra "noedit" call was part of workaround attempts which did help if i recall.

Thanks




SA Solai A L Syncfusion Team April 10, 2014 04:39 AM UTC

Hi Dave,

 

Thanks for the update.

 

Kindly refer the below provided sample with mdb file. We would very appreciate if you could reproduce the issue in the provided sample. Since, we are confused with the workarounds .Please, provide a brief description about you requirement.

 

Thanks & Regards,

AL.Solai.


Attachment: ConditionalFormatting_53fe11d1.zip


DA Dave April 10, 2014 05:03 PM UTC

Hi,

I wasn't able to reproduce with access DB, tried with 100 000+ records appended still didn't reproduce.

However was able to reproduce with MSSQL DB, same workorders select, strange is workarounds not helping reload, but resetgrid workarounds ok (select top 1...), so 5 sec delay not helping in this example.

Thanks

Attachment: ConditionalFormatting_50d72a86.zip


DA Dave April 10, 2014 05:49 PM UTC

As an aside, RecordCount keeps increasing after each reset/reload. 

TopLevelGroupOptions / CaptionText: {TableName}: {RecordCount} Items




DA Dave April 10, 2014 07:06 PM UTC

Need to make a correction, the ConditionalFormats collection is not emptied like I thought/saw, not sure how or why I saw emptied at some point days ago, regardless the color formatting is not applied on reload.


SA Solai A L Syncfusion Team April 11, 2014 11:34 AM UTC

Hi Dave,

 

Thanks for the update.

 

We regret to let you know that we couldn’t able to get what is your requirement exactly. Could you please clarify the following queries. So, that it would be easy for us to proceed further.

Queries:

1.Why have you called the reset(DB connection) method after serialization?

2.Is there any specific reason for using threads or just for workaround?.

 

We would very much appreciate if you could provide a sample with DB reproducing the issue.

 

Suggestions : the issue may be because of dataset not cleared before Deserialization or the data set used for Serialization and Deserialization are not the same.

 

Please let us know if you have any other concerns.

 

Thanks & Regards,

AL.Solai.



DA Dave April 11, 2014 04:01 PM UTC

Hi,

I'm not sure if I should send you a MSSQL 2014 database, seems with Access DB it all works fine.

The requirement is to refresh the data, either automatically because the user clicked ellipses in the grid and saved data (which could affect many rows), then it's a background thread, or the user clicked Reset or Reload buttons then it's on main thread.


1.Why have you called the reset(DB connection) method after serialization?
The serialization isn't saving any database data here, used to restore user customized styles, column order etc

2.Is there any specific reason for using threads or just for workaround?.
No not work around, as mentioned above, automatic update when user changed some data via ellipses cells, put in background to not disturb the user.

So should I attempt to send you an example along with MSSQL 2014 DB?

Thanks



SA Solai A L Syncfusion Team April 14, 2014 11:42 AM UTC

Hi Dave,

 

Thanks for the update.

 

As you said “seems with Access DB it all works fine”, we couldn't able to reproduce the issue at our end. Hence, please send the "Sample with DB" as soon as possible. So, that it would be easy for us to proceed further.

Please let us know if you have any other concerns.

 

Thanks & Regards,

AL.Solai.



DA Dave April 15, 2014 09:15 AM UTC

Hi,

Here is an MSSQL database, connection string is set to user x password: x on (local)\SQLSRV

Click Reset and Reload buttons to reproduce, Reset has a workaround that works, so might want to remove it to see the problem there.

Thanks



Attachment: ConditionalFormatting_cf2d3ca4.zip


DA Dave April 19, 2014 06:05 PM UTC

Hi,

I stumbled on another issue related to conditional formatting, click the Slow down button in example and you'll notice scrolling the grid is very slow. If conditional format isn't applied then it's fast. A strange thing is that if you run this with the profiler (Analyze / Launch performance wizard) it will be fast, so doesn't help much in tracking the problem, but certainly has to do with conditional formatting.

Thanks

Attachment: ConditionalFormatting_6a47444a.zip


SA Solai A L Syncfusion Team April 21, 2014 12:39 PM UTC

Hi Dave,

We would like to let you know that to improve the performance of Grid use conditional formatting inside “QuerycellInfo” event. This would apply conditional formatting only for those cells which are currently in view state. Kindly refer the below provided document for reference.

http://help.syncfusion.com/ug/windows%20forms/grid/default.htm#!Documents/querycellinfoevent.htm

Please let us know if you have any concerns.

Thanks & Regards,

AL.Solai.



DA Dave April 21, 2014 06:32 PM UTC

Hi,

Not sure if i understand you correctly, are you saying not to use ConditionalFormats anymore? Wouldn't need that if handling in QuerycellInfo, right?

Anyway the main reason I posted about the slow down was because it's fast when using the profiler, hardly makes sense to me, maybe you have an idea? I know the conditional format column doesn't exists in the  new select, which might explain a slow down, but why fast when profiling then?

Thanks




SA Solai A L Syncfusion Team May 3, 2014 04:20 AM UTC

Hi Dave,

Sorry for the delay.

To improve the performance of the grid, kindly refer the below provided code snippet. The following properties improves the efficiency of the grid.

Code Snippet:

#region

     this.gridGroupingControl1.AllowedOptimizations = Syncfusion.Grouping.EngineOptimizations.RecordsAsDisplayElements;

     this.gridGroupingControl1.AllowSwapDataViewWithDataTableList = true;

     this.gridGroupingControl1.UseOldListChangedHandler = true;

     this.gridGroupingControl1.UseDefaultsForFasterDrawing = true;

     this.gridGroupingControl1.UpdateDisplayFrequency = 100;

     this.gridGroupingControl1.InvalidateAllWhenListChanged = true;

     GridControlBase.UseOldHiddenScrollLogic = true;

     #endregion

Please let us know if you have any concerns.

Thanks & Regards,

AL.Solai.



DA Dave May 3, 2014 09:10 AM UTC

Hi,

I tried adding those lines to the noedit function but clicking the Slow down button remains slow. Is that reproduced on your end or just here?

Also it would be nice to have stable ConditionalFormats, any progress? It's understandable if it takes time, even a couple months as it may not be high priority.

Thanks


SA Solai A L Syncfusion Team May 10, 2014 09:57 AM UTC

Hi Dave,

Thanks for the update.

We regret to let you know that the issue("Conditional Formatting") is not reproduced at our end.Could you please report the issue with more information (and snapshot) through Direct-Trac Developer Support System (https://www.syncfusion.com/account/login?ReturnUrl=%2fsupport%2fdirecttrac%2fincidents ), because you can take the advantage of the expertise of a dedicated support engineer and a guaranteed response time and we hope you will take advantage of this system as well.

Please let us know if you have any other concerns.

Thanks & Regards,

AL.Solai.


Loader.
Up arrow icon