Checkbox problem in Datagrid

Hi Experts,
Currently I have a problem of not being able to edit the checkbox on the grid. The datagrid bound to a dataset which is filled by a DataAdapter. Since the table stored in MySql at run-time, I do not know the fields in advace, therefore I have to get data from database to dataset via Adapter. Also in MySQL boolean type is present at tinyint(1). Thus when being filled in dataset, it has "SByte" type instead of "Boolean" type .
Here is my code:

myAdapter.SelectCommand = New MySqlClient.MySqlCommand("select * from inspection_temp", myCon)
        myBuilder = New MySqlClient.MySqlCommandBuilder(myAdapter)
        myCon.Open()
        myAdapter.Fill(ds, "inspection_temp")

        format_grid()
        dg.SetDataBinding(ds, "inspection_temp")

Private Sub format_grid()
        Dim i As Integer
        Dim data_type, col_name As String
        Dim grdStyle As New DataGridTableStyle

        With grdStyle
            .MappingName = "inspection_temp"
            With .GridColumnStyles
                For i = 0 To (ds.Tables("inspection_temp").Columns.Count - 1)
                    data_type = ds.Tables("inspection_temp").Columns(i).DataType.Name
                    col_name = ds.Tables("inspection_temp").Columns(i).ColumnName
                    If data_type = "SByte" Then
                        .Add(New DataGridBoolColumn)
                    Else
                        .Add(New DataGridTextBoxColumn)
                    End If
                    With .Item(i)
                        .MappingName = col_name
                        .HeaderText = col_name
                        .ReadOnly = False
                        .NullText = ""
                    End With
                Next
            End With
        End With
        dg.TableStyles.Clear()
        dg.TableStyles.Add(grdStyle)
    End Sub

The Datagid displays grey checkbox which I can edit when having focus, but when I tab to the next cell it goes back to the grey checkbox. other columns in the datagrid are editable as they are String and Number types.
Anyone could help,please
LA
LanAnhAsked:
Who is Participating?
 
LanAnhAuthor Commented:
Thanks appari
I have tried your solution but it does not work, once the cell lost focus it goes back to grey.
However I have tried an alternative way which could solve my problem by constructing a DataTable.
         
       For i = 0 To rs.Fields.Count - 1
            col_name = rs.Fields(i).Name
            col_type = rs.Fields(i).Type
           
            Select Case col_type
                Case 5 : myColumn = New DataColumn(col_name, GetType(Double))
                Case 16 : myColumn = New DataColumn(col_name, GetType(Boolean))
                Case 133 : myColumn = New DataColumn(col_name, GetType(Date))
                Case 200 : myColumn = New DataColumn(col_name, GetType(String))
            End Select
            myTable.Columns.Add(myColumn)
        Next
        myAdapter.SelectCommand = New MySqlClient.MySqlCommand(sql, myCon)
        myBuilder = New MySqlClient.MySqlCommandBuilder(myAdapter)
        myCon.Open()
        myAdapter.fill(myTable) 'fill data to myTable
        ds.Tables.Add(myTable) 'add myTable to the dataset
        dg.SetDataBinding(ds, "inspection_temp")
So I have solve the problem in this way.
LA
0
 
appariCommented:

change

.Add(New DataGridBoolColumn)

to

       Dim boolCol As DataGridBoolColumn = New DataGridBoolColumn()
        boolCol.FalseValue = "0"
        boolCol.TrueValue = "1"
       .Add(boolCol)

change 0 and 1 to the values indicating true and false in your DB.
0
 
LanAnhAuthor Commented:
I forgot how to close this question as I have solved it myself. Any experts knows how?Thanks
0
 
appariCommented:
post a question asking for points refund in community support http://www.experts-exchange.com/Community_Support/ giving link to this question.
0
 
LanAnhAuthor Commented:
Thanks
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.