Conversion Topic is solved

Talk here about issues with one of the components hosted at wxCode, or suggest features for it.
Post Reply
Mavverick
Earned a small fee
Earned a small fee
Posts: 18
Joined: Tue Sep 09, 2008 12:14 pm
Location: Brasil

Conversion

Post 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!
timg
Earned some good credits
Earned some good credits
Posts: 148
Joined: Mon Jan 23, 2006 6:52 pm

Post 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.
Mavverick
Earned a small fee
Earned a small fee
Posts: 18
Joined: Tue Sep 09, 2008 12:14 pm
Location: Brasil

Post by Mavverick »

Hey.. thank you!!

Can you tell me now how to convert them back to string for use with SetCellValue() ??
timg
Earned some good credits
Earned some good credits
Posts: 148
Joined: Mon Jan 23, 2006 6:52 pm

Post 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)));

Post Reply