an OpenFileDialog problem

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • tlemcenvisit

    #1

    an OpenFileDialog problem

    Hello
    I am trying to open a text file, I use this code :

    private: void button1_Click(S ystem::Object^ sender, System::EventAr gs^ e)
    {
    Stream^ myStream;
    OpenFileDialog^ openFileDialog1 = gcnew OpenFileDialog;
    openFileDialog1->InitialDirecto ry = "c:\\";
    openFileDialog1->Filter = "txt files (*.txt)|*.txt|A ll files (*.*)|*.*";
    openFileDialog1->FilterIndex = 2;
    openFileDialog1->RestoreDirecto ry = true;
    if ( openFileDialog1->ShowDialog() == ::DialogResult: :OK )
    {
    if ( (myStream = openFileDialog1->OpenFile()) != nullptr )
    {
    myStream->Close();
    }
    }
    }

    The problem is that I obtain this error messages :

    error C3083: 'DialogResult': the symbol to the left of a '::' must be a type
    error C2039: 'OK' : is not a member of '`global namespace''
    error C2065: 'OK' : undeclared identifier

    All the errors are in this line :

    if ( openFileDialog1->ShowDialog() == ::DialogResult: :OK )

    Please help me
    Thanks
  • Jochen Kalmbach [MVP]

    #2
    Re: an OpenFileDialog problem

    Hi tlemcenvisit!
    [color=blue]
    > All the errors are in this line :
    >
    > if ( openFileDialog1->ShowDialog() == ::DialogResult: :OK )[/color]

    If a symbols starts with "::" it is assumed that it is in the
    global-namespace!
    So please remove the "::" at the beginning of the "DialogResult:: OK"!

    --
    Greetings
    Jochen

    My blog about Win32 and .NET

    Comment

    • tlemcenvisit

      #3
      Re: an OpenFileDialog problem

      I have doing it
      Now I have two error messages:
      e:\projets visual studio\rien\rie n\Form1.h(121) : error C2039: 'OK' : is not
      a member of 'System::Window s::Forms::Form: :DialogResult'
      e:\projets visual studio\rien\rie n\Form1.h(24) : see declaration of
      'System::Window s::Forms::Form: :DialogResult'
      e:\projets visual studio\rien\rie n\Form1.h(121) : error C2065: 'OK' :
      undeclared identifier

      Please help me

      Comment

      Working...