How do I populate a DataGridView with arrays containing strings? (I get convertion error C2664)



This is my code (only the important parts of it):

//
int Rownumber = 1;
string Rowtext[8000];
DataGridView1->Rows->Add(Rowtext[Rownumber]);
//

This code (here simplyfied) should create a row in the grid and fill
the first cell with the text stored in the array Rowtext[1] but when
debugging I get the following error message:

error C2664: 'int
System::Windows::Forms::DataGridViewRowCollection::Add(...cli::array<Type,dimension>
^)' : cannot convert parameter 1 from 'std::string' to 'System::Object
^'


If I change the code to

DataGridView1->Rows->Add("dummytext");

it WILL put the dummytext into a cell but it doesn't work if I first
declare/assign a string like this:

string strDummy = "dummytext";

and then write

DataGridView1->Rows->Add(strDummy);


I guess the Add() function can't accept a string as the argument (only
ready created inside quotemarks).

What is the solution for this? I have found a few links which could
help me, but I'm a newbie and those solutions look too complicated for
me. I just want to get rid of the error, not by refactoring the whole
code.

http://msdn2.microsoft.com/en-us/library/system.windows.forms.datagridview.columns.aspx
http://support.microsoft.com/kb/816146

.



Relevant Pages


Loading