* URGENT: DataGrid & CheckBox 
Author Message
 * URGENT: DataGrid & CheckBox

THE PROBLEM:

Standard VB Executabel using Jet OLEDB (ADO 2.1) to access
an MSAccess Database

We have a databound grid bound to a table in access, one of
the fields is an Access Yes/No field (boolean)

We want the Boolean Field to display as a checkbox. Just the same it is
displayed in Access2000 in a datagrid.

WHAT I HAVE TRIED SO FAR:

Have found an MSDN Artivle outlining Exactly how to do this
using the stdDataFormat object but, in true
microsoft form, she no werks!...i am sure this is how i did
it before but in this case it just keeps
diaplaying 0 or non zero....

Any help greatly appreciated. Below is the MSDN Example and
url to the info at msdn.

Thanx in advance

Vijay Bhatter, MCSD
http://www.{*filter*}ax.net/vijay

*********

http://www.*-*-*.com/

*********

     Option Explicit

     Private rs As ADODB.Recordset
     Private fmtBooleanData As StdDataFormat

     Private Sub Form_Load()
     Dim i As Integer

     Set rs = New ADODB.Recordset
     rs.Fields.Append "Field1", adBSTR, 64
     rs.Fields.Append "BooleanField", adBoolean
     rs.Open

     rs.AddNew
     rs.Fields("Field1").Value = "Field1"
     rs.Fields("BooleanField").Value = True
     rs.Update

     For i = 1 To 5
        rs.AddNew
        rs.Update
     Next i
     rs.MoveFirst

     Set DataGrid1.DataSource = rs

     ' set up Boolean Formatting
     Set fmtBooleanData = New StdDataFormat
     fmtBooleanData.Type = fmtBoolean
     fmtBooleanData.TrueValue = "Yes"
     fmtBooleanData.FalseValue = "No"
     fmtBooleanData.NullValue = ""

     Set DataGrid1.Columns(1).DataFormat = fmtBooleanData

     End Sub
*******************



Mon, 08 Sep 2003 19:00:26 GMT  
 * URGENT: DataGrid & CheckBox

When the code is run, you will see "Yes" in the 2nd column of the
first row, and #ERROR in the rest.

This occurs because OLE DB cannot determine what to return for an
empty non-nullable field, and therefore raises an error. Marking the
field as nullable by changing the line:

   rs.Fields.Append "BooleanField", adBoolean

to:

   rs.Fields.Append "BooleanField", adBoolean, , adFldIsNullable

On Thu, 22 Mar 2001 16:30:26 +0530, "Vijay Bhatter"

Quote:

>THE PROBLEM:

>Standard VB Executabel using Jet OLEDB (ADO 2.1) to access
>an MSAccess Database

>We have a databound grid bound to a table in access, one of
>the fields is an Access Yes/No field (boolean)

>We want the Boolean Field to display as a checkbox. Just the same it is
>displayed in Access2000 in a datagrid.

>WHAT I HAVE TRIED SO FAR:

>Have found an MSDN Artivle outlining Exactly how to do this
>using the stdDataFormat object but, in true
>microsoft form, she no werks!...i am sure this is how i did
>it before but in this case it just keeps
>diaplaying 0 or non zero....

>Any help greatly appreciated. Below is the MSDN Example and
>url to the info at msdn.

>Thanx in advance

>Vijay Bhatter, MCSD
>http://www.{*filter*}ax.net/vijay

>*********

> http://www.*-*-*.com/

>*********

>     Option Explicit

>     Private rs As ADODB.Recordset
>     Private fmtBooleanData As StdDataFormat

>     Private Sub Form_Load()
>     Dim i As Integer

>     Set rs = New ADODB.Recordset
>     rs.Fields.Append "Field1", adBSTR, 64
>     rs.Fields.Append "BooleanField", adBoolean
>     rs.Open

>     rs.AddNew
>     rs.Fields("Field1").Value = "Field1"
>     rs.Fields("BooleanField").Value = True
>     rs.Update

>     For i = 1 To 5
>        rs.AddNew
>        rs.Update
>     Next i
>     rs.MoveFirst

>     Set DataGrid1.DataSource = rs

>     ' set up Boolean Formatting
>     Set fmtBooleanData = New StdDataFormat
>     fmtBooleanData.Type = fmtBoolean
>     fmtBooleanData.TrueValue = "Yes"
>     fmtBooleanData.FalseValue = "No"
>     fmtBooleanData.NullValue = ""

>     Set DataGrid1.Columns(1).DataFormat = fmtBooleanData

>     End Sub
>*******************



Thu, 11 Sep 2003 12:11:13 GMT  
 * URGENT: DataGrid & CheckBox
When the code is run, you will see "Yes" in the 2nd column of the
first row, and #ERROR in the rest.

This occurs because OLE DB cannot determine what to return for an
empty non-nullable field, and therefore raises an error. Marking the
field as nullable by changing the line:

   rs.Fields.Append "BooleanField", adBoolean

to:

   rs.Fields.Append "BooleanField", adBoolean, , adFldIsNullable

will result in the empty fields returned as NULLs rather than errors.

On Thu, 22 Mar 2001 16:30:26 +0530, "Vijay Bhatter"

Quote:

>THE PROBLEM:

>Standard VB Executabel using Jet OLEDB (ADO 2.1) to access
>an MSAccess Database

>We have a databound grid bound to a table in access, one of
>the fields is an Access Yes/No field (boolean)

>We want the Boolean Field to display as a checkbox. Just the same it is
>displayed in Access2000 in a datagrid.

>WHAT I HAVE TRIED SO FAR:

>Have found an MSDN Artivle outlining Exactly how to do this
>using the stdDataFormat object but, in true
>microsoft form, she no werks!...i am sure this is how i did
>it before but in this case it just keeps
>diaplaying 0 or non zero....

>Any help greatly appreciated. Below is the MSDN Example and
>url to the info at msdn.

>Thanx in advance

>Vijay Bhatter, MCSD
>http://www.{*filter*}ax.net/vijay

>*********

> http://www.*-*-*.com/

>*********

>     Option Explicit

>     Private rs As ADODB.Recordset
>     Private fmtBooleanData As StdDataFormat

>     Private Sub Form_Load()
>     Dim i As Integer

>     Set rs = New ADODB.Recordset
>     rs.Fields.Append "Field1", adBSTR, 64
>     rs.Fields.Append "BooleanField", adBoolean
>     rs.Open

>     rs.AddNew
>     rs.Fields("Field1").Value = "Field1"
>     rs.Fields("BooleanField").Value = True
>     rs.Update

>     For i = 1 To 5
>        rs.AddNew
>        rs.Update
>     Next i
>     rs.MoveFirst

>     Set DataGrid1.DataSource = rs

>     ' set up Boolean Formatting
>     Set fmtBooleanData = New StdDataFormat
>     fmtBooleanData.Type = fmtBoolean
>     fmtBooleanData.TrueValue = "Yes"
>     fmtBooleanData.FalseValue = "No"
>     fmtBooleanData.NullValue = ""

>     Set DataGrid1.Columns(1).DataFormat = fmtBooleanData

>     End Sub
>*******************



Thu, 11 Sep 2003 12:11:12 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. * URGENT: DataGrid & CheckBox

2. * URGENT: DataGrid & CheckBox

3. Urgent--Datagrid &ADO & ORACLE

4. DataGrid & checkboxes

5. DataGrid & checkboxes

6. DataGrid & checkboxes

7. Checkbox format in datagrid not showing checkboxes

8. Checkbox format in datagrid not showing checkboxes

9. Need some help with DataGrids (DataGrid-->DataGrid, DataGrid-->Dataset, DataGrid-->XML)

10. listview with checkboxes!Urgent

11. DataGrid with dynamic CheckBox

12. Trapping CheckedChanged event from a checkbox on a datagrid

 

 
Powered by phpBB® Forum Software