Поделиться через


OpenFileDialog.FilterIndex Property

Microsoft Silverlight will reach end of support after October 2021. Learn more.

Gets or sets the index of the selected item in the OpenFileDialog filter drop-down list.

Namespace:  System.Windows.Controls
Assembly:  System.Windows (in System.Windows.dll)

Syntax

'Declaration
Public Property FilterIndex As Integer
public int FilterIndex { get; set; }

Property Value

Type: System.Int32
The index of the selected item in the OpenFileDialog filter drop-down list. The default is 1.

Exceptions

Exception Condition
ArgumentOutOfRangeException

The filter index is less than 1.

Remarks

This index is 1-based.

If you set the FilterIndex property, that filter will be selected when the dialog box is displayed.

Examples

The following example shows how to create an OpenFileDialog and set the Filter and FilterIndex properties.

' Create an instance of the open file dialog box.
Dim openFileDialog1 As OpenFileDialog = New OpenFileDialog

' Set filter options and filter index.
openFileDialog1.Filter = "Text Files (*.txt)|*.txt|All Files (*.*)|*.*"
openFileDialog1.FilterIndex = 1
// Create an instance of the open file dialog box.
OpenFileDialog openFileDialog1 = new OpenFileDialog();

// Set filter options and filter index.
openFileDialog1.Filter = "Text Files (.txt)|*.txt|All Files (*.*)|*.*";
openFileDialog1.FilterIndex = 1;

Version Information

Silverlight

Supported in: 5, 4, 3

Platforms

For a list of the operating systems and browsers that are supported by Silverlight, see Supported Operating Systems and Browsers.