Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Multiple types in a SaveFileDialog filter

In my SaveFileDialog I have multiple types in the filter, however when viewing the dialog if I choose a filter to view files of that type in the directory I am only able to see files for the first and last filters.

    bool save;     SaveFileDialog dlg = new SaveFileDialog();     dlg.FileName = "*";     dlg.DefaultExt = "bmp";     dlg.ValidateNames = true;      dlg.Filter = "Bitmap Image (.bmp)|*.bmp|Gif Image (.gif)|*.gif |JPEG Image (.jpeg)|*.jpeg |Png Image (.png)|*.png |Tiff Image (.tiff)|*.tiff |Wmf Image (.wmf)|*.wmf";     save = (bool)dlg.ShowDialog();      if (save)     {         SaveImage(dlg.FileName);     } 

I can see files of type .bmp and .wmf If I change the order of the filters I can always only see the first and last.

like image 680
Eamonn McEvoy Avatar asked Apr 14 '11 14:04

Eamonn McEvoy


Video Answer


2 Answers

Remove the spaces after the file type:

dlg.Filter = "Bitmap Image (.bmp)|*.bmp|Gif Image (.gif)|*.gif|JPEG Image (.jpeg)|*.jpeg|Png Image (.png)|*.png|Tiff Image (.tiff)|*.tiff|Wmf Image (.wmf)|*.wmf"; 
like image 161
Daniel Hilgarth Avatar answered Sep 23 '22 11:09

Daniel Hilgarth


FilterIndex ... DefaultExt is used just during a save. An index is 1-based so if you want to choose the 2nd option then:

dlg.FilterIndex = 2; 
like image 29
OSP Avatar answered Sep 21 '22 11:09

OSP