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 » Thu Sep 11, 2008 6:06 pm

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 » Thu Sep 11, 2008 11:33 pm

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 » Mon Sep 15, 2008 1:30 pm

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 » Mon Sep 15, 2008 5:13 pm

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