Share via


FileDialog.Filter Properti

Definisi

Mendapatkan atau mengatur string filter yang menentukan jenis file apa yang ditampilkan dari OpenFileDialog atau SaveFileDialog.

public:
 property System::String ^ Filter { System::String ^ get(); void set(System::String ^ value); };
public string Filter { get; set; }
member this.Filter : string with get, set
Public Property Filter As String

Nilai Properti

String yang berisi filter. Defaultnya adalah Empty, yang berarti bahwa tidak ada filter yang diterapkan dan semua jenis file ditampilkan.

Pengecualian

String filter tidak valid.

Contoh

Contoh berikut menunjukkan beberapa jenis string filter yang dapat diatur dengan menggunakan Filter properti .

OpenFileDialog dlg = new OpenFileDialog();

// Show all files
dlg.Filter = string.Empty;

dlg.ShowDialog();
Dim dlg As New OpenFileDialog()

' Show all files
dlg.Filter = String.Empty

dlg.ShowDialog()
OpenFileDialog dlg = new OpenFileDialog();

// Show all files
dlg.Filter = null;

dlg.ShowDialog();
Dim dlg As New OpenFileDialog()

' Show all files
dlg.Filter = Nothing

dlg.ShowDialog()
OpenFileDialog dlg = new OpenFileDialog();

// Filter by Word Documents
dlg.Filter = "Word Documents|*.doc";

dlg.ShowDialog();
Dim dlg As New OpenFileDialog()

' Filter by Word Documents
dlg.Filter = "Word Documents|*.doc"

dlg.ShowDialog()
OpenFileDialog dlg = new OpenFileDialog();

// Filter by Excel Worksheets
dlg.Filter = "Excel Worksheets|*.xls";

dlg.ShowDialog();
Dim dlg As New OpenFileDialog()

' Filter by Excel Worksheets
dlg.Filter = "Excel Worksheets|*.xls"

dlg.ShowDialog()
OpenFileDialog dlg = new OpenFileDialog();

// Filter by PowerPoint Presentations
dlg.Filter = "PowerPoint Presentations|*.ppt";

dlg.ShowDialog();
Dim dlg As New OpenFileDialog()

' Filter by PowerPoint Presentations
dlg.Filter = "PowerPoint Presentations|*.ppt"

dlg.ShowDialog()
OpenFileDialog dlg = new OpenFileDialog();

// Filter by Office Files
dlg.Filter = "Office Files|*.doc;*.xls;*.ppt";

dlg.ShowDialog();
Dim dlg As New OpenFileDialog()

' Filter by Office Files
dlg.Filter = "Office Files|*.doc;*.xls;*.ppt"

dlg.ShowDialog()
OpenFileDialog dlg = new OpenFileDialog();

// Filter by All Files
dlg.Filter = "All Files|*.*";

dlg.ShowDialog();
Dim dlg As New OpenFileDialog()

' Filter by All Files
dlg.Filter = "All Files|*.*"

dlg.ShowDialog()
OpenFileDialog dlg = new OpenFileDialog();

// Filter by Word Documents OR Excel Worksheets OR PowerPoint Presentations 
//           OR Office Files 
//           OR All Files
dlg.Filter = "Word Documents|*.doc|Excel Worksheets|*.xls|PowerPoint Presentations|*.ppt" +
             "|Office Files|*.doc;*.xls;*.ppt" +
             "|All Files|*.*";

dlg.ShowDialog();
Dim dlg As New OpenFileDialog()

' Filter by Word Documents OR Excel Worksheets OR PowerPoint Presentations 
'           OR Office Files 
'           OR All Files
dlg.Filter = "Word Documents|*.doc|Excel Worksheets|*.xls|PowerPoint Presentations|*.ppt" & "|Office Files|*.doc;*.xls;*.ppt" & "|All Files|*.*"

dlg.ShowDialog()

Keterangan

Jika Filter berupa null atau Empty, semua file ditampilkan, dan folder selalu ditampilkan.

Anda dapat menentukan subset jenis file yang akan ditampilkan dengan mengatur Filter properti . Setiap jenis file dapat mewakili jenis file tertentu, seperti berikut ini:

  • Dokumen Word (*.doc)

  • Lembar Kerja Excel (*.xls)

  • Presentasi PowerPoint (*.ppt)

Atau, jenis file dapat mewakili sekelompok jenis file terkait, seperti berikut ini:

  • File Office (*.doc, *.xls, *.ppt)

  • Semua File (*.*)

Untuk menentukan subset jenis file yang ditampilkan, Anda mengatur Filter properti dengan nilai string ( string filter) yang menentukan satu atau beberapa jenis file untuk difilter. Berikut ini memperlihatkan format string filter yang diharapkan:

FileType1[[|FileType2]...[|FileTypeN]]

Anda menggunakan format berikut untuk menjelaskan setiap jenis file:

Label|Extension1[[;Extension2]...[;ExtensionN]]

Bagian Label adalah nilai string yang dapat dibaca manusia yang menjelaskan jenis file, seperti berikut ini:

  • "Dokumen Word"

  • "Lembar Kerja Excel"

  • "Presentasi PowerPoint"

  • "File Office"

  • "Semua File"

Setiap jenis file harus dijelaskan oleh setidaknya satu Ekstensi. Jika lebih dari satu Ekstensi digunakan, setiap Ekstensi harus dipisahkan oleh titik koma (";"). Contohnya:

  • "*.doc"

  • "*.xls;"

  • "*.ppt"

  • "*.doc;*.xls;*.ppt"

  • "*.*"

Berikut ini adalah contoh lengkap nilai string yang valid Filter :

  • Word Documents|*.doc

  • Excel Worksheets|*.xls

  • PowerPoint Presentations|*.ppt

  • Office Files|*.doc;*.xls;*.ppt

  • All Files|*.*

  • Word Documents|*.doc|Excel Worksheets|*.xls|PowerPoint Presentations|*.ppt|Office Files|*.doc;*.xls;*.ppt|All Files|*.*

Setiap jenis file yang disertakan dalam filter ditambahkan sebagai item terpisah ke daftar drop-down File jenis: di OpenFileDialog atau SaveFileDialog, seperti yang ditunjukkan pada gambar berikut.

Menggunakan FileDialog.Filter dalam Kotak Dialog Buka

Pengguna dapat memilih tipe file dari daftar ini untuk difilter. Secara default, item pertama dalam daftar (misalnya, jenis file pertama) dipilih saat OpenFileDialog atau SaveFileDialog ditampilkan. Untuk menentukan bahwa jenis file lain yang akan dipilih, Anda mengatur FilterIndex properti sebelum menampilkan OpenFileDialog atau SaveFileDialog (dengan memanggil ShowDialog).

Berlaku untuk

Lihat juga