DDX Data Binding with Windows Forms Can't Find Class Method

239 views Asked by At

So I'm using Visual C++ 2013 to make a GUI application using MFC. I've embedded a C# Windows Form into the GUI using this tutorial and from there, used this tutorial, to add data binding to the Windows Form window. Now, I can use the following line in C++ to change properties of the button and text:

m_MyControl.GetControl()->textBox1->Text = "text changed";
m_MyControl.GetControl()->button1->Text = "text changed";

But when I try this same method to change properties of a chart I added to the Windows Form, like so:

m_MyControl.GetControl()->chart1->Name = "test";

then I get the error that

error C2039: 'Name' : is not a member of System::Windows::Forms::DataVisualization::Charting::Chart'

I've no idea why this is occuring since chart1 is declared public along with button1 and textBox1 inside the C# designer file. The only difference I see with these is when I hover over button1 or textbox1 in the m_Mycontrol... line I get the data type but with chart1 all I get is <'error-type'>

Any help would be greatly appreciated.

1

There are 1 answers

0
Toby On BEST ANSWER

Update: So after much pain and banging my head on my desk, I found a workaround to the problem I was having. In case anyone in the future has the same problem and comes across this post this is what worked for me: since I couldn't manipulate chart1 directly from the C++ side, but I could on the C# side, I simply added a rich textbox to the windows form, made it too small to see, hid it behind the chart, and used the

m_MyControl.GetControl()->richtextBox1->Text = " 1 2 \n 2 2 \n 3 3";

method to input data into the rich textbox I wanted put into the chart (C++ side). I then added an event handler on the C# side so that whenever the rich textbox was updated, the chart would parse the string, take that data, and plot it.

EDIT: Found the actual reason this wasn't working. Under project > properties > framework and references, I needed to add system.windows.forms.datavisualization so that VC++ knew where to find the member functions. Now I can call

m_ctrl1.GetControl()->chart1->Series[0]->Points->AddXY(0,0);

and it works just fine, adds the points to the graph and I am now a happy camper.