2

I have a Datasource which can trigger an event in order to sent data to a DataGridView. The event is triggered max 10000 times in ~1 minute. After the minute no more events will be triggered.

An Event handler receives the data. Every time I receive data, a row should be added to a DataGridView showing the information from the DataSource.

For now i have got a backgroundworker which fills a DataTable. Inside the Backgroudworker i have something like this:

DataTable dt = new DataTable()
private void ReceivedData(object sender, SomeEventArgs e)
{
     dt.Add(e.Data);
}

The problem is, that the DataGridView freezes during the process when working with more than ~300 rows. I thought about using the Virtual Mode but the problem is, that i dont know how many items i will receive and i can not count all the items before receiving them.

The goal is to show the items inside the DataGridView directly after receiving them.

JoeLiBuDa
  • 219
  • 2
  • 10
  • One way is to show in the datagridview only 200 entries and add buttons for forward and back(and of course show only 200 entries at a time). – lauCosma Apr 22 '14 at 13:21
  • Did you try to fill it with BeginInvoke and EndInvoke? – Sebi Apr 22 '14 at 13:23
  • @lauCosma I also thought about this approach but I am not very comfortable doing it like that because i wont be able to use the scrollbars anymore and altogether i will be less flexible. So i hope there are other opportunities. – JoeLiBuDa Apr 22 '14 at 13:25
  • In this case maybe you can use the scroll event and fill in the rows as you scroll. http://msdn.microsoft.com/en-us/library/system.windows.forms.datagridview.scroll(v=vs.110).aspx – lauCosma Apr 22 '14 at 13:30
  • @Sebi I made the DataTable public so that i can use DataGridView.DataSource before setting up the event handler. So when receiving, the DataGridView updates constantly but this is very slow. This is comparable to your solution right? – JoeLiBuDa Apr 22 '14 at 15:14
  • You may want to have a look at [my example](http://stackoverflow.com/a/16745054/643085) of a similar thing using current, relevant .Net Windows UI technologies. Simply change the UI (which is completely decoupled from the application logic and functionality) to suit your needs. – Federico Berasategui Apr 22 '14 at 15:25
  • @HighCore Can i use this in win forms somehow? – JoeLiBuDa Apr 22 '14 at 17:15
  • @JoeLiBuDa you can integrate WPF content into an existing winforms application using the [`ElementHost`](http://msdn.microsoft.com/en-us/library/system.windows.forms.integration.elementhost(v=vs.110).aspx). – Federico Berasategui Apr 22 '14 at 17:19

0 Answers0