6 Replies - 6949 Views - Last Post: 23 July 2013 - 05:38 AM

#1 HasanShehryar  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 4
  • Joined: 23-June 12

copy datagridview data to 2D array

Posted 22 July 2013 - 04:27 AM

I am working on a project in .NET using windows forms application. I need to copy the data from datagridview to 2D array but i am getting error. Here is my code. Here i am just trying to copy a single element to an integer.


			 int x = dataGridView1->Rows[1]->Cells[1]->Value;



the error i get is

'=' : cannot convert from 'System::Object ^' to 'int [26][9]'


Is This A Good Question/Topic? 0
  • +

Replies To: copy datagridview data to 2D array

#2 oyyou  Icon User is offline

  • D.I.C Head

Reputation: 27
  • View blog
  • Posts: 184
  • Joined: 26-April 10

Re: copy datagridview data to 2D array

Posted 22 July 2013 - 05:27 AM

Hmm.. Try changing 'x' to a var, rather than int and see what that gives you.

var x = dataGridView1->Rows[1]->Cells[1]->Value;


Was This Post Helpful? 0
  • +
  • -

#3 Michael26  Icon User is offline

  • DIC-head, major DIC-head
  • member icon

Reputation: 355
  • View blog
  • Posts: 1,524
  • Joined: 08-April 09

Re: copy datagridview data to 2D array

Posted 22 July 2013 - 05:35 AM

Thing is, C# is strongly typed language :)
What you have here is Object and Array

Quote

Here i am just trying to copy a single element to an integer.

In order to do that you need to get index of that array element and store it in the integer(that element has to be int in order to be stored inside int variable)
Was This Post Helpful? 0
  • +
  • -

#4 Curtis Rutland  Icon User is online

  • (╯□)╯︵ (~ .o.)~
  • member icon


Reputation: 4480
  • View blog
  • Posts: 7,803
  • Joined: 08-June 10

Re: copy datagridview data to 2D array

Posted 22 July 2013 - 06:29 AM

View Postoyyou, on 22 July 2013 - 07:27 AM, said:

Hmm.. Try changing 'x' to a var, rather than int and see what that gives you.

var x = dataGridView1->Rows[1]->Cells[1]->Value;



Somewhat of a bad idea. var would make that specific error go away, but then x would be whatever type that he was trying to force into that integer. He's not going to be able to make use of it correctly later. Also, why are you using the dereferencing operator? Are you storing dataGridView1 as a pointer? Is this C++ or C# code?
Was This Post Helpful? 0
  • +
  • -

#5 HasanShehryar  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 4
  • Joined: 23-June 12

Re: copy datagridview data to 2D array

Posted 22 July 2013 - 11:37 PM

this is a c++ code and i found it on internet. if u guys know any other way do let me know. anyways thanks for ur precious time
Was This Post Helpful? 0
  • +
  • -

#6 Skydiver  Icon User is online

  • Code herder
  • member icon

Reputation: 3569
  • View blog
  • Posts: 11,089
  • Joined: 05-May 12

Re: copy datagridview data to 2D array

Posted 23 July 2013 - 05:23 AM

Ahh, you are trying to write C++/CLI code.

Moving to the C++/CLI forum...
Was This Post Helpful? 0
  • +
  • -

#7 snoopy11  Icon User is offline

  • Engineering ● Software
  • member icon

Reputation: 773
  • View blog
  • Posts: 2,287
  • Joined: 20-March 10

Re: copy datagridview data to 2D array

Posted 23 July 2013 - 05:38 AM

Hi,

I think your missing a ^ in your code

Is it not int ^ x =

Regards

Snoopy.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1