{"id":1174,"date":"2015-05-27T11:56:09","date_gmt":"2015-05-27T11:56:09","guid":{"rendered":"http:\/\/mindfusion.eu\/blog\/?p=1174"},"modified":"2021-01-15T15:38:05","modified_gmt":"2021-01-15T15:38:05","slug":"winforms-spreadsheet-auto-filtering","status":"publish","type":"post","link":"https:\/\/mindfusion.dev\/blog\/winforms-spreadsheet-auto-filtering\/","title":{"rendered":"WinForms Spreadsheet Auto-Filtering"},"content":{"rendered":"<p>In this post we will discuss how to use the auto-filtering feature in MindFusion.Spreadsheet for WinForms.<\/p>\n<p><strong>Introduction<\/strong><\/p>\n<p>We start off by creating a new Windows Forms Application in Visual Studio, adding a <a href=\"http:\/\/www.mindfusion.dev\/onlinehelp\/spreadsheetwinforms\/index.htm?T_MindFusion_Spreadsheet_WorkbookView.htm\">WorkbookView<\/a> control to the main form and adding the Northwind database (nwind.mdb) as a data source. For simplicity we only add the Orders table. After compiling the application we can add the DataSource and the OrdersTableAdapter as components to the main form.<\/p>\n<p><strong>Loading the data<\/strong><\/p>\n<p>We traverse the rows in the data source and populate the spreadsheet by assigning the data to the <a href=\"http:\/\/www.mindfusion.dev\/onlinehelp\/spreadsheetwinforms\/index.htm?P_MindFusion_Spreadsheet_Cell_Data_0.htm\">Data<\/a> property of the respective worksheet cells. The first cell in each column is set to the name of the corresponding database field. Finally, the columns are resized to fit their contents through the <a href=\"http:\/\/www.mindfusion.dev\/onlinehelp\/spreadsheetwinforms\/index.htm?M_MindFusion_Spreadsheet_WorkbookView_ResizeColumnsToFit_2_Int32_Int32.htm\">ResizeColumnsToFit<\/a> method of the view. The complete code of the data loading can be found in the <strong>LoadData<\/strong> method.<\/p>\n<p><strong>Turning auto-filtering on<\/strong><\/p>\n<p>Auto-filtering is enabled by calling the <a href=\"http:\/\/www.mindfusion.dev\/onlinehelp\/spreadsheetwinforms\/index.htm?M_MindFusion_Spreadsheet_CellRange_AutoFilter_0.htm\">AutoFilter<\/a> method of the <a href=\"http:\/\/www.mindfusion.dev\/onlinehelp\/spreadsheetwinforms\/index.htm?T_MindFusion_Spreadsheet_CellRange.htm\">CellRange<\/a> class. If the <strong>CellRange<\/strong> represents a range of cells, then auto-filtering is applied to that range. If the <strong>CellRange<\/strong> represents a single cell, then auto-filtering is applied to the rectangular area of data cells, which includes this cell. In this application, we enable auto-filtering on the loaded data, by calling <strong>AutoFilter<\/strong> on cell A1. In addition, we apply auto-filtering criteria on the 6-th column (ShipVia) by calling the <a href=\"http:\/\/www.mindfusion.dev\/onlinehelp\/spreadsheetwinforms\/index.htm?M_MindFusion_Spreadsheet_CellRange_AutoFilter_5_Int32_Object_AutoFilterOperator_Object_Boolean.htm\">AutoFilter<\/a> overload.<\/p>\n<pre>workbook1.Worksheets[0].CellRanges[\"A1\"].AutoFilter();\nworkbook1.Worksheets[0].CellRanges[\"A1\"].AutoFilter(\n    6, \"&lt;&gt;1\", AutoFilterOperator.Or, null, true);<\/pre>\n<p>The following image shows the running sample:<br \/>\n<a href=\"http:\/\/mindfusion.dev\/blog\/wp-content\/uploads\/2015\/05\/spreadsheet-autofilter.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-medium wp-image-1177\" src=\"http:\/\/mindfusion.dev\/blog\/wp-content\/uploads\/2015\/05\/spreadsheet-autofilter-300x214.png\" alt=\"spreadsheet-autofilter\" width=\"300\" height=\"214\" srcset=\"https:\/\/mindfusion.dev\/blog\/wp-content\/uploads\/2015\/05\/spreadsheet-autofilter-300x214.png 300w, https:\/\/mindfusion.dev\/blog\/wp-content\/uploads\/2015\/05\/spreadsheet-autofilter-420x300.png 420w, https:\/\/mindfusion.dev\/blog\/wp-content\/uploads\/2015\/05\/spreadsheet-autofilter.png 739w\" sizes=\"auto, (max-width: 300px) 100vw, 300px\" \/><\/a><\/p>\n<p>The source code is available for download from here:<br \/>\n<a href=\"https:\/\/mindfusion.dev\/_samples\/SpreadsheetAutoFilter.zip\">https:\/\/mindfusion.dev\/_samples\/SpreadsheetAutoFilter.zip<\/a><\/p>\n<p>MindFusion.Spreadsheet for WinForms can be downloaded from here:<br \/>\n<a href=\"https:\/\/mindfusion.dev\/SpreadsheetTrial.zip\">MindFusion.Spreadsheet for WinForms<\/a><\/p>\n<p><em>About MindFusion.Spreadsheet for WinForms<\/em>: A powerful .net spreadsheet component with great capabilities for editing, styling and formatting large amounts of data.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>In this post we will discuss how to use the auto-filtering feature in MindFusion.Spreadsheet for WinForms. Introduction We start off by creating a new Windows Forms Application in Visual Studio, adding a WorkbookView control to the main form and adding &hellip; <a href=\"https:\/\/mindfusion.dev\/blog\/winforms-spreadsheet-auto-filtering\/\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":3,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":true,"jetpack_social_options":{"image_generator_settings":{"template":"highway","enabled":false},"version":2}},"categories":[74,163],"tags":[309,193,165,164,192],"class_list":["post-1174","post","type-post","status-publish","format-standard","hentry","category-sample-code","category-spreadsheet","tag-autofilter","tag-database","tag-excel","tag-spreadsheet-2","tag-worksheet"],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack_shortlink":"https:\/\/wp.me\/p3RlKs-iW","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/mindfusion.dev\/blog\/wp-json\/wp\/v2\/posts\/1174","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/mindfusion.dev\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/mindfusion.dev\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/mindfusion.dev\/blog\/wp-json\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/mindfusion.dev\/blog\/wp-json\/wp\/v2\/comments?post=1174"}],"version-history":[{"count":5,"href":"https:\/\/mindfusion.dev\/blog\/wp-json\/wp\/v2\/posts\/1174\/revisions"}],"predecessor-version":[{"id":2541,"href":"https:\/\/mindfusion.dev\/blog\/wp-json\/wp\/v2\/posts\/1174\/revisions\/2541"}],"wp:attachment":[{"href":"https:\/\/mindfusion.dev\/blog\/wp-json\/wp\/v2\/media?parent=1174"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/mindfusion.dev\/blog\/wp-json\/wp\/v2\/categories?post=1174"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/mindfusion.dev\/blog\/wp-json\/wp\/v2\/tags?post=1174"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}