error C2440: 'argument' : cannot convert from 'System::Object ^' to 'int'
this is my code:
for (q = 0; q < Rows; q++)
{
for (r = 0; r < Columns; r++)
{
Array1[q, r] = combo1->Items[r];
Array2[q, r] = combo2->Items[r];
}
}
I want to add items in arrays from combo boxes but I am getting the err开发者_StackOverflowor:
error C2440: 'argument' : cannot convert from 'System::Object ^' to 'int'
this is the code which is adding items in combo
for (int m = 0; m < Rows; m++)
{
array<String^> ^b = Aray1[m]->Split(gcnew array<Char> { ',' });
for each (String ^Column in b)
{
Combo1->Items->Add(Column);
}
}
Assuming that you're using C++/CLI.
Judging by the error it looks like the Array1
elements are typed to int
and the combo box contains values wrapped in an ObjecT^
. If the value is truly just an int
being wrapped in an Object^
then you just need to unbox
Array1[q,r] = safe_cast<int>(combo1->Items[r]);
Array2[q,r] = safe_cast<int>(combo2->Items[r]);
This will fall if the Object^
is actually wrapping another type besides int
精彩评论