[RESOLVED] DataGridView not painting itself correctly
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2

Thread: [RESOLVED] DataGridView not painting itself correctly

  1. #1
    Join Date
    May 2007
    Location
    Denmark
    Posts
    623

    [RESOLVED] DataGridView not painting itself correctly

    I have this code:

    Code:
    private void GetErrors()
    {
        errors = GetFailedTasks();
    
        for (int i = 0; i < errors.Count; i++)
        {
            Task t = errors[i];
            if(gridAlerts.Rows.Count <= i)
                gridAlerts.Rows.Add(new DataGridViewRow());
            gridAlerts["_ID", i].Value = t.ID;
            gridAlerts["_Severity", i].Value = t.Severity;
            gridAlerts["_Customer", i].Value = t.Customer;
            gridAlerts["_Unit", i].Value = t.Unit;
            gridAlerts["_IP", i].Value = t.IP;
            gridAlerts["_Type", i].Value = t.Type;
            gridAlerts["_Limit", i].Value = t.LimitString;
            gridAlerts["_Time", i].Value = t.TimeString;
            gridAlerts["_Message", i].Value = t.Message;
    
            switch (t.DownColor)
            {
                case "red":
                    gridAlerts["_Severity", i].Style = red;
                    break;
                case "yellow":
                    gridAlerts["_Severity", i].Style = yellow;
                    break;
                case "green":
                    gridAlerts["_Severity", i].Style = green;
                    break;
            }
        }
    
        for (int i = gridAlerts.Rows.Count - 1; i >= errors.Count; i--)
            gridAlerts.Rows.RemoveAt(i);
    }
    which is executed every 2 seconds on my form. Whenever the code adds or removes one or more rows, it ends up looking like this:



    I've tried:

    Code:
    gridAlerts.UpdateCellValue(cell, row);
    gridAlerts.Update();
    gridAlerts.CommitEdit();
    But nothing has made any difference.

    The point of manipulating the rows like this is to maintain the scrollbar position...

    Does anyone have a suggestion?
    It's not a bug, it's a feature!

  2. #2
    Join Date
    May 2007
    Location
    Denmark
    Posts
    623

    Re: DataGridView not painting itself correctly

    Solved: The datagridview's defaultcellstyle contained some transparent colors, which were the cause of the problems
    It's not a bug, it's a feature!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center