ファイル ダイアログ ボックスで現在選択されているフィルタのインデックスを取得または設定します。
Public Property FilterIndex As Integer
[C#]
public int FilterIndex {get; set;}
[C++]
public: __property int get_FilterIndex();public: __property void set_FilterIndex(int);
[JScript]
public function get FilterIndex() : int;public function set FilterIndex(int);
プロパティ値
ファイル ダイアログ ボックスで現在選択されているフィルタのインデックスを含む値。既定値は、1 です。
解説
ユーザーに最初に表示するフィルタ処理オプションを設定するには、 FilterIndex プロパティを使用します。また、ファイル ダイアログ ボックスを表示した後でも、 FilterIndex の値を使用すると、選択されたフィルタに応じて特別なファイル処理を実行できます。
メモ 1 番目のフィルタ エントリのインデックス値は 1 です。
使用例
[Visual Basic, C#, C++] FileDialog の OpenFileDialog 実装を使用し、ダイアログ ボックスの作成、そのプロパティの設定、およびダイアログ ボックスの表示を実行する例を次に示します。この例では、 Filter プロパティと FilterIndex プロパティを使用して、表示するフィルタのリストを指定しています。この例は、フォームに Button が配置され、 System.IO 名前空間が追加されていることを前提にしています。
Protected Sub button1_Click(sender As Object, e As System.EventArgs)
Dim myStream As Stream
Dim openFileDialog1 As New OpenFileDialog()
openFileDialog1.InitialDirectory = "c:\"
openFileDialog1.Filter = "txt files (*.txt)|*.txt|All files (*.*)|*.*"
openFileDialog1.FilterIndex = 2
openFileDialog1.RestoreDirectory = True
If openFileDialog1.ShowDialog() = DialogResult.OK Then
myStream = openFileDialog1.OpenFile()
If Not (myStream Is Nothing) Then
' Insert code to read the stream here.
myStream.Close()
End If
End If
End Sub
[C#]
protected void button1_Click(object sender, System.EventArgs e)
{
Stream myStream;
OpenFileDialog openFileDialog1 = new OpenFileDialog();
openFileDialog1.InitialDirectory = "c:\\" ;
openFileDialog1.Filter = "txt files (*.txt)|*.txt|All files (*.*)|*.*" ;
openFileDialog1.FilterIndex = 2 ;
openFileDialog1.RestoreDirectory = true ;
if(openFileDialog1.ShowDialog() == DialogResult.OK)
{
if((myStream = openFileDialog1.OpenFile())!= null)
{
// Insert code to read the stream here.
myStream.Close();
}
}
}
[C++]
protected:
void button1_Click(Object* /*sender*/, System::EventArgs* /*e*/)
{
Stream* myStream;
OpenFileDialog* openFileDialog1 = new OpenFileDialog();
openFileDialog1->InitialDirectory = S"c:\\" ;
openFileDialog1->Filter = S"txt files (*.txt)|*.txt|All files (*.*)|*.*" ;
openFileDialog1->FilterIndex = 2 ;
openFileDialog1->RestoreDirectory = true ;
if(openFileDialog1->ShowDialog() == DialogResult::OK)
{
if((myStream = openFileDialog1->OpenFile())!= 0)
{
// Insert code to read the stream here.
myStream->Close();
}
}
}
[JScript] JScript のサンプルはありません。Visual Basic、C#、および C++ のサンプルを表示するには、このページの左上隅にある言語のフィルタ ボタン をクリックします。
必要条件
プラットフォーム: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 ファミリ, .NET Compact Framework - Windows CE .NET
参照
FileDialog クラス | FileDialog メンバ | System.Windows.Forms 名前空間 | CheckFileExists | Filter