On Visual Studio C# Express when I run the script below, I get the following error message on the line saying:
if (ofd.ShowDialog() == true): Error 1 Operator '==' cannot be applied to operands of type 'System.Windows.Forms.DialogResult' and 'bool'
How could I solve this? Code below:
public override GH_ObjectResponse RespondToMouseDoubleClick(GH_Canvas sender, GH_CanvasMouseEvent e)
{
System.Windows.Forms.OpenFileDialog ofd = new System.Windows.Forms.OpenFileDialog();
ofd.Multiselect = true;
ofd.Filter = "Data Sources (*.ini)|*.ini*|All Files|*.*";
if (ofd.ShowDialog() == true)
{
string[] filePath = ofd.FileNames;
string[] safeFilePath = ofd.SafeFileNames;
}
return base.RespondToMouseDoubleClick(sender, e);
}
Replace it with:
ShowDialog
method returns DialogResult enumeration, which has following members:Compare with on of the values defined for
DialogResult
like DialogResult.OK not boolean.Possible values of DialogResults are given below. compare with the one you require.
I suspect you've been reading the WPF
OpenFileDialog.ShowDialog
documentation where the method result isNullable<bool>
. If, however, you're using Windows FormsOpenFileDialog.ShowDialog
, that returnsDialogResult
- which you clearly can't compare withbool
.Have a look at
DialogResult
and see what you actually want to do. Note that the documentation claims:... so those should be the only cases you need to consider.