Problem with hidden operations in tab_page side of a tab_control?

1

Hi, I have a new question, I have 1 tab_control with 2 tab_pages, both tab_pages have a datagridview that loads MySQL data, in the first tab_page it shows a list of clients, and in the second it shows a list of calls, which by means of a timer (with interval of 1 second) they are marked in red, when they are not called in their programmed strip.

Well, the problem is that if the tab_page1 is active, the 2nd Tab_page does not shade the rows with exceeded time in red until that tab_page2 is active, from there it just starts to shade in red but skips the first rows , you may skip more or less rows, depending on how long it takes me to activate that tab_page2, if I delay too long do not shades in red, none.

How to execute those processes in tab_page2 so that it shadows the dgw rows without that tab needing to be active?

In this example you can see that only 2 rows were activated because it took me 2 seconds to change from tab_page1 to this tab_page

    
asked by neojosh2 03.04.2017 в 03:34
source

1 answer

0

As I told you in my comment, I think you have the problem by manually coloring the datagrid. The best way to colorize rows in a DataGridView is to use the event CellFormatting . This event is triggered each time the grid must paint a cell. In your case, what I would do would be the following:

Form builder

this.dgw_dXp.CellFormatting += 
               new DataGridViewCellFormattingEventHandler(this.dgw_dXp_CellFormatting);

CellFormatting handler

private void dgw_dXp_CellFormatting(object sender, DataGridViewCellFormattingEventArgs e)
{
    TimeSpan TiempoTotal = Convert.ToDateTime(dgw_dXp.Rows[e.RowIndex].Cells[0].Value.ToString()) - DateTime.Now;
    segundos = Convert.ToDouble(TiempoTotal.TotalSeconds.ToString());
    if (segundos < 1)
    { 
        dgw_dXp.Rows[e.RowIndex].DefaultCellStyle.BackColor=Color.Red;
    }
    else
    {
        dgw_dXp.Rows[e.RowIndex].DefaultCellStyle.BackColor=Color.White;
    }
}

With this I think that when changing tabs you should update the rows correctly. As you want to be updated every minute, in your timer you do this:

Timer

private void t_Contador_Tick(object sender, EventArgs e)
{
    dgw_dXp.Refresh();
}

I think that doing it this way, everything will work as expected.

    
answered by 04.04.2017 / 11:11
source