3
Answers

datagridview scrolling problem

ruben laureys

ruben laureys

14y
6.9k
1
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.

 public partial class SnifferPanel : UserControl {

        public bool running = false;
        DataTable d;

        public SnifferPanel() {
            d = new DataTable();
            d.Columns.Add("Source");
            d.Columns.Add("Destination");
            d.Columns.Add("UID");
            d.Columns.Add("Index");
            d.Columns.Add("Mode");
            d.Columns.Add("Data");
            
            InitializeComponent();
            BindingSource b = new BindingSource();
            b.DataSource = d;
            dataGridViewSniffer.DataSource = b;
        }

        public void newData(Emulator.Modulemanager.RS485Data data) {            
            if (running) {
                dataGridViewSniffer.SuspendLayout();
                string[] da = { data.Address, data.Address, data.Uid, data.Index, data.Mode, data.Data };
                d.Rows.Add(da);
                dataGridViewSniffer.ResumeLayout();
            }
        }
}

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)