Main Site Documentation

DataGrid, Speed Problem?


#1

History of my project so you know what I’m doing.
I am monitoring 2 temperature sensors, one in a remote well location connected via Xbee and the other sensor is connected to the Spider board. Each sensor generates it’s own event. I am taking a reading of both sensors every 10 minutes.
I would like to store a half a days of events in the DataGrid object. That comes to 144 events. My DataGrid displays 9 lines at a time on the screen and there are 5 columns in the DataGrid.
Here is the problem, it appears that every time a new event (item) is added to the DataGrid and then Invalidate is called, all events (items) are processed. So each item that an item is add, it will slow the Invalidate call down a little. When you get a lot of items in the DataGrid, it can take a half a second to process.

I did a quick fix to verify this and now it works a lot better. Adding a new item does not add to the Invalidate call execute time. ScrollUp and ScrollDown works ok but the DataGrid tap and scroll does not work as I have it now.

Below is what I changed in the DataGrid.cs source file:
This is in public override void Render()
/******************************************
if (_rows.Count > 0)
{
for (int i = 0; i < _rows.Count; i++)
UpdateItem(i, false);
}
* ****************************************/

            if (_rows.Count > 0)
	   {
	   // Display the list, in my case, 9 lines (displayable lines).
	  int index = (_rows.Count - RowCount);
	 // Adjust for ScrollUp or ScrollDown.
	 index -= _scrollIndex;
	 // Lets now crash if we can avoid it.
	 if(index < 0)
	    index = 0;

	 // Do each displayable line.
	 for(int i = 0; i < RowCount; ++i)
	    {
	    // Another just-in-case check.
	   if(index >= _rows.Count)
	      break;

	   if(index == _selectedIndex)
	     RenderItem(i, ((DataGridItem)_rows[index]).Data, SelectedItemBackColor, SelectedItemFontColor);
	   else
	     {
	     if(index % 2 == 0)
		 RenderItem(i, ((DataGridItem)_rows[index]).Data, ItemsBackColor, ItemsFontColor);
	    else
		 RenderItem(i, ((DataGridItem)_rows[index]).Data, ItemsAltBackColor, ItemsFontColor);
             }		// end-of else if(index == _selectedIndex)
						 
	++index;
	 }			// end-of for(int i = 0; i < RowCount; ++i)
        }				// end-of if (_rows.Count > 0)
  }					// end-of if (_renderItems)

I then set __renderItems in both the ScrollUp & ScrollDown methods.

The question is, can anything be done to speed up the Invalidate call when a large number of items have been added?


#2

The main reason it is so slow is that it draws every item in the list on a bitmap behind the scenes, while only a portion of this is actually displayed. We will look into optimizing this, but for now, you could consider a paging solution instead of infinite scrolling.


#3

I have modified the DataGrid code so that it works without slowing down.
At this point it works great for my current project.
Even the tap-and-scroll works.

I am in the process of more testing on my version of the DataGrid.

With guest coming this week and getting ready to spend some time in Florida to get out of this cold weather, I’m not sure how much time I’ll have for this project for awhile.