Page 1 of 1

Conversion

Posted: Thu Sep 11, 2008 6:06 pm
by Mavverick
Hello

I'm kinda new in C++ programming and wxWidgets.. and I am trying to use a wxGrid for a matrix insertion.
So I want to get the values of each cell with GetCellValue and store in a matrix

Code: Select all

matrix<double> A(n,n);
.
So I have a code to invert the matrix so that after I could display the inverted matrix in another wxGrid.
But I'm getting an error message that says "cannot convert 'wxString' to 'double' in assingment"
Is there a way that I can get to do what I'm trying to?
If yes, can anyone tell me how?

Thanks!

Posted: Thu Sep 11, 2008 11:33 pm
by timg
wxGrid.GetCellValue returns a string since the base wxGrid stores its data as strings.

If you want to assign the values returned from GetCellValue to an array of doubles, you should do:

Code: Select all

double temp_val;
m_grid.GetCellValue(row,col).ToDouble(&temp_val);

A(row,col) = temp_val;
When you assign the values back to the grid after your manipulation, you need to convert them back to string for use with SetCellValue() as well.

Posted: Mon Sep 15, 2008 1:30 pm
by Mavverick
Hey.. thank you!!

Can you tell me now how to convert them back to string for use with SetCellValue() ??

Posted: Mon Sep 15, 2008 5:13 pm
by timg
you can do it many ways. Here's one:

Code: Select all


m_grid.SetCellValue(row,col,wxString::Format("%f",A(row,col)));