By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
431,983 Members | 1,717 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 431,983 IT Pros & Developers. It's quick & easy.

Faster way to update datagridview?

P: 6

I am currently developing an GUI that contains a datagridview. The datasource for the gridview is an ArrayList. I have had som problems adding new rows to the datagrid while the GUI was running. I finaly got it to add a new row when I clicked a button, but when the number of datarows exeeds about 10 rows it starts to be slow to add rows. This is because it has to refresh all the data for every new row added. Do you guys know a way to add a row to the datagrid without having to refresh all the data. My code for adding a new row is the following:

Expand|Select|Wrap|Line Numbers
  2.         // Event triggered when the user wants to add an aditional command row to his datagridview.
  3.         private void AddCommandButton_Click(object sender, EventArgs e)
  4.         {
  5.             CommandClass MyDataLine = new CommandClass();       // This is the objects that fills the datagrid
  6.             commandLineList.Add(MyDataLine);                    // Adds the new object to the data source of the datagrid
  7.             dataGridView1.DataBindings.Clear();                 // Clears databindings
  8.             dataGridView1.DataSource = null;                    // Clears data source
  9.             dataGridView1.DataSource = commandLineList;         // Sets the correct data source
  10.             ComboBoxValueSelect();                              // Updates the values of a combobox contained in the gridview
  11.         }
Nov 15 '10 #1
Share this question for a faster answer!
Share on Google+

Post your reply

Sign in to post your reply or Sign up for a free account.