TasostheGreat
TasostheGreat

Reputation: 442

Where do I have to put the code?

I have an application which downloads some data and I want to show that data on a listView. By deafault Mfc shows me some code, a namepace and a class with that listView. There is also a seperate cpp file with a main with this code:

int main(array<System::String ^> ^args)
{
    Application::EnableVisualStyles();
    Application::SetCompatibleTextRenderingDefault(false); 

    // Hauptfenster erstellen und ausführen
    Application::Run(gcnew Form1());

    return 0;
}

I don't know where to put my function in this main which downloads stuff, and how to address and alter this listView

inside the main this doesn't work:

Form1->listView1->Text = "asdasdasdasd"

Upvotes: 0

Views: 166

Answers (2)

Ajay
Ajay

Reputation: 18431

A quick solution:

Form1 theForm = gcnew Form1();
theForm->listView1->Text = "Text here";
Application::Run(theForm);

But you should implement the same in one of the events for Form (like Load event).

Upvotes: 0

Alex F
Alex F

Reputation: 43331

This is not MFC, this is C++/CLI with Windows Forms. You need to place your code to some Form1 event handler, for example, Load event handler. Double-click Form1 in Design view to create event handler, and place your code there.

Later you may improve the program logic by handling some button events (for example, add Download button and handle its Click event) and using background threads. But on the first step just try Form.Load event.

Upvotes: 1

Related Questions