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);
}
I suspect you’ve been reading the WPF
OpenFileDialog.ShowDialogdocumentation 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
DialogResultand see what you actually want to do. Note that the documentation claims:… so those should be the only cases you need to consider.