Manually set blink state depending on blink state of other columns

Hi there,
 
I have a trading grid where the bid and offer price fluctuate. These columns are updating correctly in regards to their Blink state.
However I'd like certain other columns to match the blinkstate. So far i can see the current blink state but the updating doesn't seem to work.
In the linked image you can easily see what i mean, but basically:
column 1 blinkstate need to match column 2's blink state and column 4 need to match column 3's blink state.
 
<code>
                grid.Engine.AddBaseStylesForBlinking();        //Uptick style
                grid.BaseStyles[GridEngine.BlinkIncreased].StyleInfo.TextColor = Color.Black;
                grid.BaseStyles[GridEngine.BlinkIncreased].StyleInfo.BackColor = Colors.Green;
 
                grid.BaseStyles[GridEngine.BlinkReduced].StyleInfo.TextColor = Color.White;
                grid.BaseStyles[GridEngine.BlinkReduced].StyleInfo.BackColor = Colors.Red;
 
                //Note that another requirement for Blinking is an optimization piece of code as follows:
                //If optimization is not used then uncomment this code
                //grid.UseDefaultsForFasterDrawing = true;            //Enables Blinking as well
 
                #region --Blink entire row if new Row is added
                grid.Engine.BaseStyles.Add("NewRowStyle"); //used in this code for new rows
                grid.BaseStyles["NewRowStyle"].StyleInfo.TextColor = Color.White;
                grid.BaseStyles["NewRowStyle"].StyleInfo.BackColor = Color.Green;
                grid.TableControlPrepareViewStyleInfo += new GridTableControlPrepareViewStyleInfoEventHandler(gridGroupingControl1_TableControlPrepareViewStyleInfo);
 
...
...
         void gridGroupingControl1_TableControlPrepareViewStyleInfo(object sender, GridTableControlPrepareViewStyleInfoEventArgs e)
        {
            #region --Blink entire row if new Row is added
            GridTableCellStyleInfo style = (GridTableCellStyleInfo)e.Inner.Style;
            BlinkState bs = gridGroupingControl1.GetBlinkState(style.TableCellIdentity);
 
            if (bs != BlinkState.None)
            {
                if (bs == BlinkState.NewRecord)
                {
                    e.Inner.Style.BaseStyle = "NewRowStyle";
                }
            }
 
            Record r = style.TableCellIdentity.DisplayElement.GetRecord();    //Get record for selected cell
            if (r != null)
            {
                if (e.Inner.ColIndex == 1)
                {
                    FieldDescriptor desc = this.gridGroupingControl1.TableDescriptor.Fields[nameof(tblTOB.BestBidPrice)];
                    BlinkState bsBidPrice = gridGroupingControl1.GetBlinkState(r, desc);
                    if (bs != BlinkState.None)
                    {
                        if (bs == BlinkState.Increased)
                        {
                            e.Inner.Style.BaseStyle = this.gridGroupingControl1.BaseStyles[GridEngine.BlinkIncreased].Name;
                        }
                        else if (bs == BlinkState.Reduced)
                        {
                            e.Inner.Style.BaseStyle = this.gridGroupingControl1.BaseStyles[GridEngine.BlinkReduced].Name;
                        }
                    }
                }
            }
            #endregion
        }
 
</code>
  

Example

 

 

 


3 Replies

AR Arulpriya Ramalingam Syncfusion Team December 13, 2017 12:18 PM UTC

Hi James, 
 
Thanks for contacting Syncfusion support. 
 
We have analyzed your requirement and suspect that you are trying to blink the cells based on another cell value of the record. The blink state will be updated for a particular cell based it’s cell value. So, the grid does not have the support to blink a cell based on another cell value. This can be achieved by using the QueryCellStyleInfo event. In that event, the record can be retrieved by using the GetRecord() method of DisplayElements and the cell value of a particular column can be retrieved by using GetValue() method of Record. Moreover, the BackColor property can be used to update the style of the based on conditions. We have created a simple sample as per your requirement. In the attached sample, the “CategoryName” column style is update based on the “SampleData” column value and the “Phone” column style is updated based on the cell value of “Description” column. Please make use of the below code and sample, 
 
Code example 
 
//Event Triggering 
this.gridGroupingControl1.QueryCellStyleInfo += GridGroupingControl1_QueryCellStyleInfo; 
 
//Event customization 
private void GridGroupingControl1_QueryCellStyleInfo(object sender, GridTableCellStyleInfoEventArgs e) 
{ 
    Record record = e.TableCellIdentity.DisplayElement.GetRecord(); 
    if (e.TableCellIdentity.Column == null || record == null) 
        return; 
    if (record.Kind == DisplayElementKind.Record) 
    { 
        string description = record.GetValue("Description").ToString(); 
        string sampleData = record.GetValue("SampleData").ToString(); 
 
        if (e.TableCellIdentity.TableCellType != GridTableCellType.ColumnHeaderCell 
             && e.TableCellIdentity.Column.Name == "Phone" && description == "Desc10") 
        { 
            //To highlight the Phone column cells based on cell value of Description 
            e.Style.BackColor = Color.Green; 
            e.Style.TextColor = Color.White; 
        } 
        if (e.TableCellIdentity.TableCellType != GridTableCellType.ColumnHeaderCell && 
            e.TableCellIdentity.Column.Name == "CategoryName" && sampleData == "Data43") 
        { 
            //To highlight the CategoryName column cells based on cell value of sampleData 
            e.Style.BackColor = Color.HotPink; 
            e.Style.TextColor = Color.White; 
        } 
    } 
} 
 
 
Please let us know if we misunderstood your requirement. 
 
Regards, 
Arulpriya 



JR James Roodt December 14, 2017 08:15 AM UTC

Hi Arulpriya,

Your suspicion is both true and untrue. I need to set the cell background state according to the state of another cell.
BUT not based on it's value but based on it's blink state.

Basically the grid is devided into two halves with a column in each half driving that half. If the column goes up that column blinks correctly.
BUT i want the entire 'half' of the grid associated with that column to blink with it regardless of the values inside them.
So it will be as if the entire half or the row blinks instead of just the one cell.

As it is the blink state I need to synchronise with I cannot use the value of the column because it will always be a random number for me. I need to know if that value increased or decreased in relation to it's previous value. (However the blink also needs to end so i will also need to reset that background) It should be easier if i can manually set the blink state of the other cells as to synchronise with the column driving these cells.

Regards,
James


MG Mohanraj Gunasekaran Syncfusion Team December 15, 2017 01:06 PM UTC

Hi James, 
 
Sorry for the inconvenience caused. 
 
By default, GridGroupingControl blink state does not have the direct support to change the back color based on another cell value. But, you can achieve your scenario based on Record.GetValue and Record.GetOldValue method in QueryCellStyleInfo event. Please refer to the below code example and the sample, 
 
Code example 
this.gridGroupingControl1.QueryCellStyleInfo += GridGroupingControl1_QueryCellStyleInfo; 
 
private void GridGroupingControl1_QueryCellStyleInfo(object sender, GridTableCellStyleInfoEventArgs e) 
{ 
    Record record = e.TableCellIdentity.DisplayElement.GetRecord(); 
    if (e.TableCellIdentity.Column == null || record == null) 
        return; 
    if (record.Kind == DisplayElementKind.Record) 
    { 
        if (e.TableCellIdentity.Column.Name == "Description") 
        { 
            Int32 value = Convert.ToInt32(record.GetValue("Value")); 
            int fieldIndex = this.gridGroupingControl1.TableDescriptor.ColIndexToField(e.Style.CellIdentity.ColIndex); 
            Int32 oldValue = Convert.ToInt32(record.GetOldValue(e.Style.CellIdentity.ColIndex)); 
                int cmp = CompareColumns.CompareNullableObjects(value, oldValue); 
                if (cmp > 0) 
                    e.Style.BackColor = Color.Green; 
                else 
                    e.Style.BackColor = Color.Red; 
 
        } 
    } 
} 
 
 
Sample link: GridGroupingControl 
 
Please let us know if you have any concerns. 
 
Regards, 
Mohanraj G  
 


Loader.
Up arrow icon