Jimbo99999
asked on
VB.Net - DataGrid Change ColumnType
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
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).
DataGridRow.Cells(4).Value
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
is the source a string or a decimal?
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).Defaul tCellStyle .Format = "c"
If DataGridRow.Cells(4) is a Numeric value, then you cannot add the currency symbol. You can format it as Currency:
DataGrid.Columns(4).Defaul
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).
ASKER
Thanks for your responses. Please don't mark as neglected as I was off for the holiday.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
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.