Best way to fill DataGridView with large amount of data

前端 未结 6 1594
不思量自难忘°
不思量自难忘° 2020-11-30 05:43

I have a windows form that has two DataGridViews (DGVs) that will hold 25,000+ records and 21 columns each. I have successfully loaded each with the data from the DB using

6条回答
  •  轻奢々
    轻奢々 (楼主)
    2020-11-30 06:20

    I'm not sure this is quite what you're asking, but I like to create a subset of data to intitially load, and then include search functionality. This is very easy to do using visual studio 15 and DataSources / data sets. In solution explorer, open your dataset.xsd file. It will be named DataSet.xsd Go to the Data Table in question. Right-click, and add a query. One thing I commonly do is just add "TOP 1000" to my query. So, select * from mytable becomes select TOP 1000 * from mytable

    Finally, double-click on your form to find your _load method, and alter the "Fill" to use your new query. This might be best demonstrated with an example:

    The first line of code that I commented out is what Vis Stud created by default. The second is the one I added, which will get only the top 1000 records.

            private void Form_Customers_Load(object sender, EventArgs e)
        {
            // TODO: This line of code loads data into the 'stage2DataSet.customers' table. You can move, or remove it, as needed.
            /* this.customersTableAdapter.Fill(this.stage2DataSet.customers); */
            this.customersTableAdapter.FillBy_Top_1000(this.stage2DataSet.customers);
    
    
        }
    

提交回复
热议问题