开发者

Binding and Searching Large DataTable

开发者 https://www.devze.com 2023-04-12 22:46 出处:网络
I have implemented Auto Complete drop down list in WPF It is giving issues when a large data (say over 30 MB) is bind to it

I have implemented Auto Complete drop down list in WPF

It is giving issues when a large data (say over 30 MB) is bind to it

What is the best ap开发者_开发问答proach to work on large data (Operations like Searching)

Is it possible to serialize 30 MB data and as User type in Autocomplete Drop Down List, Search

in to serialized data and attach resulting data to Drop Down List and show it to the User

Please suggest...


Usually you should put time-consuming operations in BackgroundWorker.DoWork event handler not setting controls properties as above. if you want to set a property of control which have been created in another thread in BackgroundWorker.DoWork event handler then you should use Control.Invoke method to set properties asynchronously. nevertherless following code is better solution:

   toolStripStatusLabel1.Text = "Loading ... ";


enter code here` backgroundWorker1.RunWorkerAsync();

enter code here`backgroundWorker1_DoWork(/*arguments*/)
{
// getting data from database and fill dataset
}

backgroundWorker1_RunWorkerCompleted(/*arguments*/)
{
            dt_kh = ds.Tables[0];

            cboMaKH.DataSource = ds.Tables[0];
            cboMaKH.DisplayMember = "MaKH";
            cboMaKH.ValueMember = "MaKH";


            cboTenCty.DataSource = ds.Tables[0];
            cboTenCty.DisplayMember = "TenCty";
            cboTenCty.ValueMember = "TenCty";

            cboMaKH.AutoCompleteMode = AutoCompleteMode.SuggestAppend; 
            cboMaKH.AutoCompleteSource = AutoCompleteSource.CustomSource;
            cboMaKH.AutoCompleteSource = AutoCompleteSource.ListItems;
            cboTenCty.AutoCompleteMode = AutoCompleteMode.SuggestAppend;
            cboTenCty.AutoCompleteSource = AutoCompleteSource.CustomSource;
            cboTenCty.AutoCompleteSource = AutoCompleteSource.ListItems;

            txtTenKH.DataBindings.Add("Text", ds.Tables[0], "TenKH");
            txtDiaChi.DataBindings.Add("Text", ds.Tables[0], "Diachicty");
            txtDienThoai.DataBindings.Add("Text", ds.Tables[0], "DienThoaiCty");
            txtTaiKhoan.DataBindings.Add("Text", ds.Tables[0], "TaiKhoanCty");
            txtVIMST.DataBindings.Add("Text", ds.Tables[0], "MSTCty");
}


Is your autocomplete textbox using ICollectionView.Filter to search values?

If yes then it is bound to be slow for large data sets being synchronous.

Use PLINQ to your advantage.

When a user types a text in the textbox, perform the PLINQ query to entries that start with \ contain the text that is typed, and then rebind the itemssource after the PLINQ query returns.

If you cant use PLINQ or dont have .Net 4.0, then perform the simple LINQ search on a different thread and rebind over the Dispatcher of the autocomplete box.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号