datagridview scrolling problem

Mar 18 2010 8:36 AM
I have a form with a datagridview to which rows are being added at runtime (data that comes in, about one row per second at this time, will become much more). There is no problem as long as the number of rows fits the size of the datagridview. When the data doesn't fit the datagridview, a vertical scrollbar appears. When I attempt to scroll, the application hangs.

I've tried stopping the dataflow, and then scrolling but this gives the same problem.
Also the scrollbar arrows are not drawn. 
  1. public partial class SnifferPanel : UserControl   
  2. {  
  3.    public bool running = false;  
  4.    DataTable d;  
  5.      
  6.    public SnifferPanel()   
  7.    {  
  8.       d = new DataTable();  
  9.       d.Columns.Add("Source");  
  10.       d.Columns.Add("Destination");  
  11.       d.Columns.Add("UID");  
  12.       d.Columns.Add("Index");  
  13.       d.Columns.Add("Mode");  
  14.       d.Columns.Add("Data");  
  15.       InitializeComponent();  
  16.       BindingSource b = new BindingSource();  
  17.       b.DataSource = d;  
  18.       dataGridViewSniffer.DataSource = b;  
  19.    }  
  20.   
  21.    public void newData(Emulator.Modulemanager.RS485Data data)   
  22.    {              
  23.       if (running)   
  24.       {  
  25.          dataGridViewSniffer.SuspendLayout();  
  26.          string[] da = { data.Address, data.Address, data.Uid, data.Index, data.Mode, data.Data };  
  27.          d.Rows.Add(da);  
  28.          dataGridViewSniffer.ResumeLayout();  
  29.       }  
  30.    }  
  31. }  
The newData function is called from a class that handles the incoming data, this class runs in a seperate thread.
I hope someone here can help me out.

edit: Wow, my code looks horrible. Can anyone tell me how to properly align code on the forum?

Answers (3)