Click here to Skip to main content
15,884,099 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hi.
I am trying to load some information from a query into a datagridView.
This query return an integer and some decimals.

After loading the information into the DataGridView , I need to take that first number and format it ( it is a date, so I change it from (int) yyyymmdd format to (string) dd/mm/yyyy , but the datagridview seems to ask for an int32 ValueType.

I tried to change the Cell ValueType to String type. After changing it (and checking if it really is string type now) it still asks for an int32 format value.

Any idea of what is happening?

DG.DataSource = //Function giving a data table             
DG.Columns[0].ValueType = typeof(String);
for (int i = 0; i < DG.Rows.Count; i++)
{
    string a = //Function returning date format string, dd/mm/yyyy
    DG.Rows[i].Cells[0].Value = a;
}


UPDATE:
Resolved by OP himself. Posted the answer as one of the solutions below.
Posted
Updated 6-Apr-11 8:49am
v2

1 solution

I solved it changing a little the sql statement:


MYDATE (INT TYPE ON DATABASE)


Instead of doing :

SELECT MYDATE FROM TABLE

which made the field on the DataGridView be an Int32, I changed to:

SELECT CAST(MYDATE AS VARCHAR(8)) MYDATE FROM TABLE

This way, the DataGridView makes that field string type, and I can change it with no problem.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900