Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
130
Highlight changed cells failed after first few runs
posted

I have two timers to  control highligh/cancel value changed cells.  It works well only for the first few runs, then no highlight happens even cell values are still changed. Could you please shet any light of how that happened?   Here are my codes:

 public Form1() {

        myHighlighter = new Timer(); myHighlighter.Enabled = true; myHighlighter.Interval=5000; myHighlighter.Tick += HighLightChangedCells;

        myCleaner = new Timer(); myCleaner.Enabled = true; myCleaner.Interval=1000; myCleaner.Tick += CancelHighlights;      
 }

private void HighLightChangedCells(object sender, EventArgs e)

{

      myCleaner.Stop();

      DataTable dtNew = GetRandomData();

      ultraGridView1.DataSource = dtNew;

      foreach(UltraGridRow row in ultraGridView.Rows)

      {

           int i=row.Index;

           int iNewValue = Convert.ToInt32( dtNew.Rows[i][0]);

           int iSavedValue = savedValueArray[i];

           if( iNewValue > iSavedValue )

                 row.Cells[0].Appearance = styleIncreased;

          else if( iNewValue < iSavedValue )

                row.Cells[0].Appearance = styleDecreased;  

      }     
      ultraGridView1.Refresh();

      SavePreviousValues(dtNew);

     myCleaner.Start();

 

}

private void CancelHighlights(object sender, EventArgs e)

{

     foreach(UltraGridRow row in ultraGridView1.Rows)

                  row.Cells[0].Appearance.BackColor = Color.White;

private DataTable GetRandomData() 

{

    DataTable dtRet = new DataTable();

    Random rnd = new Random();
 

     for(int i=0; i<SIZE; i++)

     {

             DataRow dr = dtRet.NewRow();

             dr["Value"] = rnd.Next(100, 1000);

             dtRet.Rows.Add(dr);

     }

     return dtRet;

}

private void Form1_Load(object sender, EventArgs e)

{

     ultraGridView1.DataSource = GetRandomData(); 

      myHighlighter.Start();


private void SavePreviousValues(DataTable dt)

{

    for(int i=0; i<SIZE; i++)

              savedValueArray[i] = Convert.ToInt32(dt.Rows[i][0]) ;