|
-
Oct 31st, 2010, 01:37 PM
#1
Thread Starter
Hyperactive Member
Datagridview with lots of rows
Hi,
I'm working on a project which uses a datagridview to show some data.
The data is loaded from a xml file (which the code parse the xml, and create datagridview cell dynamically). and the user is allowed to change the data, when the program exists, it will write back to the xml file to save the change.
It works fine when there are not many rows. when it has too many rows, say, 10K rows, the program loads slowly.
I searched, found some suggestions, but it seems they do not work very well.
1) when load the data, not create the rows directly. instead, create a datatable, then add the table to the datagridview's data source. it still takes time for the dgv to show the data.
2) then, I guess maybe I should paging the dgv. then it comes 2 questions:
2.a) I only have a manually created table, how can I get a dataadapter/dataset from it? do I have to put data in a database table first (i.e. sql express), then load it to data adapter? is it possible to manually create a data adapter/dataset?
2.b) if I paging the dgv, does it mean I still need manually update the dataset/datatable to keep the possible change when the user navigate through the dgv? or, I can simply use an update method?
The paging method I mentioned is at here: http://www.vb-tips.com/PageDataGridView.aspx
Right now, the solution I have is: since I have the table already, I'll use paging method for the table directly. at the load event, load all data to a global table first, then for a page, clone the table, and only add rows in that page to the clone table, then set the dgv's source as the cloned table. this way, the dgv only holds the rows in that page, if changes happened, then update the global table.
or, I should use a database for this, i.e. sql express? any other suggestions?
thanks
-
Oct 31st, 2010, 01:51 PM
#2
Member
Re: Datagridview with lots of rows
Too many rows?
Does your program just keep adding rows to the xml file and not just overwrite it?
If you already have SQL Express as your data storage, you shouldn't mind adding more rows in your XML File.
In my opinion- Using XML from SQL is just a way to bridge data from different database application(e.g. Sql Express to Mysql transferring)
If you have time kind of problem, I can surely help you 100%,
-
Oct 31st, 2010, 03:07 PM
#3
Thread Starter
Hyperactive Member
Re: Datagridview with lots of rows
thanks for reply. however, the problem is:
the data is actually saved in xml file first (from another application's output). I load the xml, parse it, then use the data to fill in the datagridview. but, there are so much data, it takes time to load. it also creates some problems when navigating through the rows. that's why I think of paging.
thanks again.
-
Oct 31st, 2010, 04:22 PM
#4
Member
Re: Datagridview with lots of rows
If your XML data record sequence is in first and last order, follow this procedure.
Here some sequences that I could think of:
General Method:
1. Export all the XML data to DGV and use that DGV to export/insert to SQLExpress(Even though it takes time, all data should be exported)
2. Count the exported dataset/datatable's row count(mydatatable.Row.Count = ToThisInteger)
3. Create a table in SQLExpress that records the current rowcount of dataset/datable.
4. Insert/Update the ToThisInteger variable to your newly created table in SQL.
2nd Method(Your Updated XML file's will record the data that hasn't been recorded to your SQLExpress)
1. Export the Updated XML Files to a dataset and count that dataset's RowCount and put it on a variable(e.g: myDataset.Rowcount = XMLRowcount).
2. Get the recorded Rowcount from SQLExpress and apply it to a other Variable.
Load the RowCount table from SQL into a datagrid and get the value of it and apply it to a variable.
3. Compare the XML's dataset's rowcount to your Previous RowCount which is recorded in your created table in SQLExpress.
4. If the RowCount in your SQLExpress = 1000 and the Updated XML dataset RowCount = 1010 then
Subtract the SQLExpress recorded rowcount to Updated XML dataset Rowcount and yet again, put it on a variable. (e.g:
Dim XMLRowCount as Integer = myDataset.Rowcount
Dim SQLExpressRowCount Integer = RowCountThatIRecordedFromSQL
Dim WillAddData as Integer = XMLRowCount - SQLExpressRowcount <--- Value of this is now lessen to 10
)
5. Now import the Updated XML to a dataset/datatable like this:
Dim myDataset as New Dataset <-- Load the Updated XML File in this one.
Dim myDataTable As New Datatable
myDataset.Fill(myDatatable, SQLExpressRowCount, XMLRowCount)
Form1.Datagridview.Datasource = myDatatable
When it's imported to the datagrid, you will see the datas that hasn't been really added to your SQLExpress database.
it's up to you on how you'd INSERT those data in your SQLExpress from Form1.Datagridview output.
I hope it helps ^__^;
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|