How to send information to DataGridView->DataSource in Visual Studio 2022 C++ Winforms

Viewed 98

I have a problem with DataGridView->DataSource, I don't understand how to compile my program.

On C# I have the solution but not in C++:

Working C#:

Entry.cs

public class Entry
{ 
    public int Property1 { get; set; }
    public string Property2 { get; set; }
}

Form1.cs

var data = new List<Entry>();
data.Add(new Entry() { Property1 = 1, Property2 = "One" });
data.Add(new Entry() { Property1 = 2, Property2 = "Two" });
data.Add(new Entry() { Property1 = 3, Property2 = "Three" });
dataGridView1.DataSource = data;

And in C++

Entry.h

#pragma once
#include <string>
ref class Entry
{
public:
    int Property1;
    int Property2;
    //std::string* Property2;
};

MainForm.h

private: System::Void MainForm_Load(System::Object^ sender, System::EventArgs^ e) {
    //System::Windows::Forms::DataGridView::DataSource = data;
    std::vector<Entry> data;
    Entry entry;
    entry.Property1 = 1;
    entry.Property2 = 2;
    data.push_back(entry);
    entry.Property1 = 3;
    entry.Property2 = 4;
    data.push_back(entry);
    entry.Property1 = 5;
    entry.Property2 = 6;
    data.push_back(entry);
    dataGridViewLeft->DataSource = data; // Only dataGridViewLeft is underlined in red
}

Thanks in advance

0 Answers
Related