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).dataf ormat = xxxx
Thanks
for example :
DataGrid1.Columns(0).dataf
Thanks
should be able to...it is read/write at design time and run time
Yes you can
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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
Set col4 = FormMDI.DataGrid1.Columns(
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
ASKER
But NumberFormat don't work with the boolean type.....
ASKER
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
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
.Columns(0).Alignment = dbgCenter
.Columns(1).NumberFormat = "standard"
.Columns(1).Alignment = dbgRight
ASKER
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.....
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>.
Regardless.. please provide some information about your database connection.. <smile>.
ASKER
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.OL EDB.3.51;P ersist Security Info=False;Data Source=" & PathDB & NomeDB
I use an adodc control to connect datagrid and databse:
FormMDI.Adodc1.RecordSourc e = Sql
FormMDI.Adodc1.Refresh
Set FormMDI.DataGrid1.DataSour ce = FormMDI.Adodc1.Recordset
you have an idea ?
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.OL
I use an adodc control to connect datagrid and databse:
FormMDI.Adodc1.RecordSourc
FormMDI.Adodc1.Refresh
Set FormMDI.DataGrid1.DataSour
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>.
"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>.
ASKER
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
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