VB.Net - DataGrid Change ColumnType

Jimbo99999
Jimbo99999 used Ask the Experts™
on
Good Day Experts!

I gave it a valiant effort but I am really out of ideas.  I have a DataGrid with double data values in 5 columns as received from a DataTable.  I do not have the DataGrid column formatted as currency.

I need to be able to iterate through the DataGrid and based on a string value in the first column put a $ or £ in front of the double value.  Here is what I am trying:

Dim Amount As String = CStr(DataGridRow.Cells(4).Value)
DataGridRow.Cells(4).Value = "$" & Amount

Unfortunately I am getting an error --> Not a valid value for type decimal

It feels like the DataGrid is holding onto the type "assigned" from the DataTable but I am not sure.

Can you help with ideas?

Thanks,
jimbo99999
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Top Expert 2016

Commented:
is the source a string or a decimal?
Most Valuable Expert 2012
Top Expert 2014

Commented:
Assuming you're using a DataGridView:

If DataGridRow.Cells(4) is a Numeric value, then you cannot add the currency symbol. You can format it as Currency:

DataGrid.Columns(4).DefaultCellStyle.Format = "c"

It feels like the DataGrid is holding onto the type "assigned" from the DataTable but I am not sure.
AFAIK, you cannot change the Datatype of a Datagridview Column after it's created. You'd have to instead create a new column with your desired type, and fill it as needed. You can set the Column DataPropertyName to the column in your underlying dataset, and the grid should show the values in that column (assuming they're compliant with the column's datatype, of course).

Author

Commented:
Thanks for your responses.  Please don't mark as neglected as I was off for the holiday.
I ended up taking the currency designation off the column.  Then Interrogated the Datagrid formatting the value to decimal then converting to a String so I could add the "£" or "$" designation.  

Thanks for your responses,
jimbo99999

Author

Commented:
I didn't want to delete the question since I found a solution on my own.  I wanted to share it for others to use that may be in the same situation.

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial