Link to home
Start Free TrialLog in
Avatar of AlessandroF
AlessandroF

asked on

Dataformat with Datagrid

Can I set in a datagrid (6.0) the Dataformat for a specific columns via visual basic code ?

for example :

 DataGrid1.Columns(0).dataformat = xxxx

Thanks
Avatar of AzraSound
AzraSound
Flag of United States of America image

should be able to...it is read/write at design time and run time
Avatar of riduce
riduce

Yes you can
ASKER CERTIFIED SOLUTION
Avatar of wsh2
wsh2

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of AlessandroF

ASKER

The solution offers from Wsh2 is Ok but complicated, after a weekend-brainstorming I have write this code that change the format of a datagrid columuns:

Set col4 = FormMDI.DataGrid1.Columns(4)
With FormMDI.DataGrid1
     .Columns(0).Caption= "Manuale"
     .Columns(1).Caption = "Revisione"
     .Columns(2).Caption = "Descrizione"
     .Columns(3).Caption = "Data"
     .Columns(4).Caption = "Attivo"
      col4.NumberFormat = CBool(.Columns(4).Value)
end with


But NumberFormat don't work with the boolean type.....
Wsh2 I'am not able to declare:

Dim WithEvents f1 as StdDataFormat

because in my project StdDataFormat is unknow, I read the Msdn relative documet but I not understand.....

Thanks




       .Columns(0).NumberFormat = "short date"
        .Columns(0).Alignment = dbgCenter
            .Columns(1).NumberFormat = "standard"
            .Columns(1).Alignment = dbgRight
Jannea thanks for response but I have in the columns Boolean value written -1 and 0.
I must write True and False...I have just use NumberFormat but not work with the boolean type.....
Wait a second.. it sounds like in your database you have this field defined as Integer rather than boolean (True/False). If so.. change the database field data type to boolean (ie True/False) and everything should be ok.
Regardless.. please provide some information about your database connection.. <smile>.
The proble is that I can't use the solution offers by Wsh2 because I'am not able to declare:

Dim WithEvents f1 as StdDataFormat

because in my project StdDataFormat is unknow I Open database with:

Set DB = New ADODB.Connection   DB.Open "Provider=Microsoft.Jet.OLEDB.3.51;Persist Security Info=False;Data Source=" & PathDB & NomeDB

I use an adodc control to connect datagrid and databse:

FormMDI.Adodc1.RecordSource = Sql
FormMDI.Adodc1.Refresh
Set FormMDI.DataGrid1.DataSource = FormMDI.Adodc1.Recordset

you have an idea ?

Alessandrof, Did you do this?

"From the Project menu, set references to the Microsoft Data Formatting Object Library" and the Microsoft Data Binding Collection."

That is where your definitions are.. <smile>.

Ok I write in my code:

Dim WithEvents f1 As StdDataFormatSet f1 = New StdDataFormat
f1.Type = fmtBoolean

f1.FalseValue = "Non attivo"
f1.TrueValue = "Attivo"
Set .Columns(5).DataFormat = f1

I can now set the datagrid.dataformat Thanks.
Ciao