Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to check what filter is applied

I am developing exporting data in xpdl format. There are 2 options - version 2.1 and 2.2. I am using SaveFileDialog, but how can I distinguish between those 2 options?

        SaveFileDialog dlg = new SaveFileDialog();
        dlg.Filter = "xpdl 2.1|*.xpdl|xpdl 2.2|*.xpdl";
        if (dlg.ShowDialog() == System.Windows.Forms.DialogResult.OK)
        {
            //how can I check, which format is selected?
        }
like image 981
user1582878 Avatar asked Aug 15 '12 06:08

user1582878


2 Answers

Split the Filter list. Then look at the FilterIndex.

SaveFileDialog dlg = new SaveFileDialog();
dlg.Filter = "xpdl 2.1|*.xpdl|xpdl 2.2|*.xpdl";
if (dlg.ShowDialog() == System.Windows.Forms.DialogResult.OK)
{
    string[] filterstring = saveFilaDialog.Filter.Split('|');
    MessageBox.Show(filterstring[(saveFilaDialog.FilterIndex - 1) * 2]);
}
like image 148
sarathi Avatar answered Oct 07 '22 19:10

sarathi


You can get or set selected filter for dialogs by checking FilterIndex property. And as stated in msdn:

The index value of the first filter entry is 1.

So for your task it would be:

        SaveFileDialog dlg = new SaveFileDialog();
        dlg.Filter = "xpdl 2.1|*.xpdl|xpdl 2.2|*.xpdl";
        if (dlg.ShowDialog() == System.Windows.Forms.DialogResult.OK)
        {
            switch (dlg.FilterIndex)
            {
                case 1:
                    //selected xpdl 2.1
                    break;
                case 2:
                    //selected xpdl 2.2
                    break;
            }
        }
like image 22
JleruOHeP Avatar answered Oct 07 '22 20:10

JleruOHeP