Click to See Complete Forum and Search --> : Custom types formating and parsing in a DataGridView


modlfo
July 26th, 2007, 04:44 AM
Hi to everyone!

I got a problem that is easier to explain in code. I made a class to hold a custom data type. And I'm using an ArrayList to store a list of my custom types. In order to edit the data I've assigned the ArrayList to the DataGridView. Overriding the ToString function I can represent my custom type as a string. I have a parsing function that converts a string to my data but I don't know how to make that the DataGridView control use it when I edit a cell.

An example is this.

public ref class ComplexNum
{
double re;
double im;
public:
ComplexNum()
{
re=im=0;
}
public:
virtual String^ ToString() override
{
return re.ToString()+"+"+im.ToString()+"*i";
}
}

void somefunction(void)
{
//Declare and initialize a DatGridView named dgv1

ArrayList^ data1=gcnew ArrayList;

data1->Add(gcnew ComplexNum());
data1->Add(gcnew ComplexNum());

dgv1->DataSource=data1;

}



Thanks.