Using a C++ object as a data source  
Author Message
CJPO





PostPosted: Visual C++ General, Using a C++ object as a data source Top

Hello,

I'm using Vs2005 C++ and .Net 2.0 and creating a Windows Form Application so that I can use the DataGridView control. I want the DataGridView to be bond to a data source which is a C++ object.

If look at documentation on how to do this it says that any object with at least one public property can be used. And there are examples on how to do this, but the big frustration of being a C++ programmer in a .Net world is that the only example is in C#. Normally the syntax is close enough that I can translate it, but in this case I'm missing something fundimental.

If I create a class with a public property like this in it:

property unsigned Id

{

unsigned get();

}

And then run Data Source Configuration Wizard, this class is not listed as choice. Clearly I'm missing something that lets the Wizard understand my Class/Object is available. Judging from the C# example either "public property" means something else, or C# does this registration automatically, and C++ doesn't.

Thank you for your help.




Visual C++2  
 
 
Mike Danes





PostPosted: Visual C++ General, Using a C++ object as a data source Top

For any object to appear in that wizard you must first build the project. Did you do it
 
 
CJPO





PostPosted: Visual C++ General, Using a C++ object as a data source Top

Yes I built it, lots of times, in many different combinations. I read that in the documentation. Don't know what I'm missing...

Oh well my current tack is just to blow off the GUI, and bind it myself. As a matter of fact I decided just to go with a BindingSource, and have my data classes bind to that.

Thanks for the suggestion.



 
 
Mike Danes





PostPosted: Visual C++ General, Using a C++ object as a data source Top

Is your class public


 
 
CJPO





PostPosted: Visual C++ General, Using a C++ object as a data source Top

Yes it is public, but it looks like I found the problem, and shows that I probally should have posted the whole class. This is the code where it doesn't show up.

namespace OM

{

generic<typename T>

public ref class OMList : public List<T>

{

public:

OMList();

OMList(String ^newDate,

unsigned refNum,

String ^newDescription,

String ^newClr,

double newAmount,

String ^memo

);

virtual ~OMList(void);

property String ^date;

property unsigned refNum;

property String ^description;

property String ^clr;

property double ^amount;

property String ^memo;

};

}

If I drop the generic, which required dropping sub classing from List<T> it then appears in the Wizard.

I tried also where I kept the generic, but didn't sub class from List<T> and it doesn't appear in the Wizard. So it seems like generics are not covered by the Wizard.



 
 
Mike Danes





PostPosted: Visual C++ General, Using a C++ object as a data source Top

Yes, to use a generic type as a datasource you need to specify the type parameter but the wizard does not know how to do it.