New to Telerik UI for WPF? Download free 30-day trial

Filtering

With the R3 2017 SP 1 version of Telerik UI for WPF, you can now specify a filter for the RadOpenFileDialog and RadSaveFileDialog dialogs in order to indicate to the user which types of files should be opened or saved. To enable this functionality you can set the Filter and FilterIndex properties.

The Filter is a property of type string that determines what file extensions should be used in the combo. On the other hand, the FilterIndex property can be used to get or set the index of the filter currently selected in a file dialog.

The index value of the first filter entry is 1.

The string set to the Filter property is parsed in a strict way. So when parsing is not successful, the following ArgumentException is thrown:

Provided filter string is not valid. Filter string should contain a description of the filter, followed by a vertical bar and the filter pattern. Must also separate multiple filter description and pattern pairs by a vertical bar. Must separate multiple extensions in a filter pattern with a semicolon. Example: "Image files (*.bmp, *.jpg)|*.bmp;*.jpg|All files (*.*)|*.*"

Filter in RadOpenFileDialog

To set a filter for the RadOpenFileDialog dialog you can set the Filter property. When this property is not set the combo box will not appear.

Example 1: Set Filter property of RadOpenFileDialog

RadOpenFileDialog openFileDialog = new RadOpenFileDialog(); 
openFileDialog.FileName = "Document"; 
openFileDialog.Filter = "Word Documents|*.doc|Excel Worksheets|*.xls;*.xlsx|" + 
                        "PowerPoint Presentations|*.ppt" + 
                        "|Office Files|*.doc;*.xls;*.xlsx;*.ppt" + 
                        "|Image Files|*.jpg;*.png" + 
                        "|Text Files|*.txt;" + 
                        "|Archives Files|*.zip;*.rar" + 
                        "|All Files|*.*"; 
openFileDialog.FilterIndex = 2; 
openFileDialog.ShowDialog(); 

Figure 1: Filter combo box visualization in RadOpenFileDialog

Filter combo box in RadOpenFileDialog

Filter in RadSaveFileDialog

To set a filter for the RadSaveFileDialog dialog you can set the Filter property. When this property is not set the combo box will appear but will be empty.

Note that the filter property does not only filter the files in the main pane but also determines the type of the file which will be saved.

Example 2: Set Filter property of RadSaveFileDialog

RadSaveFileDialog saveFileDialog = new RadSaveFileDialog(); 
saveFileDialog.FileName = "Document"; 
saveFileDialog.Filter = "Word Documents|*.doc|Excel Worksheets|*.xls;*.xlsx|" + 
                        "PowerPoint Presentations|*.ppt" + 
                        "|Office Files|*.doc;*.xls;*.xlsx;*.ppt" + 
                        "|Image Files|*.jpg;*.png" + 
                        "|Text Files|*.txt;" + 
                        "|Archives Files|*.zip;*.rar" + 
                        "|All Files|*.*"; 
saveFileDialog.FilterIndex = 2; 
saveFileDialog.ShowDialog(); 

Figure 2: Filter combo box visualization in RadSaveFileDialog

Filter combo box in RadSaveFileDialog

See Also

In this article