(Type your message here)
I use bool column in my datagrid. but I get all grayed checkswhen I first load it. I know it is about the DBNULL state, but ihave set Col.AllowNull = False. my column data type is tinyint,1 or 0. So after I get these value, i convert it to true orfalse.Anyway, i have tried all the way i can think about, itstill not work. can you help? thanks.
I post my code here.
Private Sub frmModComps_Load(ByVal sender As System.Object, ByVale As System.EventArgs) Handles MyBase.Load
conString = "....."
daModComps = New OdbcDataAdapter("....." ,conString)
daModComps.Fill(ds, "table")
CustimizeDataGrid()
Dim i As Integer
With dsModComps.Tables(0)
For i = 0 To .Rows.Count - 1
If .Rows(i)("active") = 1 Then
.Rows(i)("active") =Convert.ToBoolean(.Rows(i)("active"))
ElseIf .Rows(i)("active") = 0 Then
.Rows(i)("active") =Convert.ToBoolean(.Rows(i)("active"))
End If
Console.WriteLine(Convert.ToBoolean(.Rows(i)("acti ve")))
Next
End With
grdModComps.DataSource = dsModComps.Tables(0)
End Sub
Private Sub CustimizeDataGrid()
Dim dgts As DataGridTableStyle = NewDataGridTableStyle()
dgts.MappingName = "table"
grid.TableStyles.Clear()
'1. Add a first column style
Dim desCol As New DataGridTextBoxColumn()
desCol.MappingName = "Description"
desCol.HeaderText = "Type"
desCol.Alignment = HorizontalAlignment.Center
desCol.ReadOnly = True
dgts.GridColumnStyles.Add(desCol)
'2. Add a second column style.
Dim activeCol As New DataGridBoolColumn()
activeCol.MappingName = "Active"
activeCol.HeaderText = "Active"
activeCol.AllowNull = False
activeCol.Alignment = HorizontalAlignment.Center
dgts.GridColumnStyles.Add(activeCol)
'3. Add a third column style.
Dim weightCol As New DataGridTextBoxColumn()
weightCol.MappingName = "Weight"
weightCol.HeaderText = "Weight"
weightCol.Alignment = HorizontalAlignment.Center
dgts.GridColumnStyles.Add(weightCol)
' 4. set column width
dgts.GridColumnStyles(0).Width = 150
dgts.GridColumnStyles(1).Width = 100
dgts.GridColumnStyles(2).Width = 87
dgts.DataGrid.Refresh()
grd.TableStyles.Clear()
grd.TableStyles.Add(dgts)
End Sub
--------------------------------
From: Alice April
-----------------------
Posted by a user from .NET 247 (http://www.dotnet247.com/)
<Id>zXnHJROmUEichwy3kbtSfA==</Id>