PDA

نسخه کامل مشاهده نسخه کامل : کپی بخشی از داده ای دیتاست در گرید



mohammad0511
13-06-2016, 11:33
سلام دوستان
من یک دیتاست دارم که با دستور fill از دیتابیسم اون رو پر می کنم اما به دلیل حجم زیادی که اطلاعات داره نمی خوام همه ی اطلاعات رو یک دفعه توی گرید بریزم. چون یک کم هنگ می کنه. آیا راه حلی هست که مثلا 100 رکورد اول رو توی گرید نشون بدم و بعدش با هر سرچی که کاربر انجام میده 100 رکورد اول مرتبط با سرچ نشون داده بشه. اگر هم راه حل بهتری داره راهنمایی کنید لطفا. فقط سرعت لود شدن و سرچ کردن برام خیلی مهمه.
ممنون

akpa
22-06-2016, 12:27
Create the rows manually in a loop, as you are currently doing: as you have noticed, it's very inefficient if you have a lot of data


Use the DataGridView's virtual mode, as suggested by Jonathan in his comment: the DGV only creates as many rows as can be displayed, and dynamically changes their contents when the user scrolls. You need to handle the CellValueNeeded event to provide the required data to the DGV

Use databinding: that's by far the easiest way. You just fill a DataTable with the data from the database using a DbDataAdapter, and you assign this DataTable to the DGV's DataSource property. The DGV can automatically create the columns (AutoGenerateColumns = true), or you can create them manually (you must set the DataPropertyName of the column to the name of the field you want to display). In databound mode, the DGV works like in virtual mode except that it takes care of fetching the data from the datasource, so you don't have anything to do. It's very efficient even for a large number of rows