Hide Boolean Col in DataGrid

W

Wayne Wengert

I have a datagrid bound to dataset where some entries are null. In that grid
I am defining a column as Boolean (see code below) and I get the expected
checkbox which is checked or unchecked when the DB value is 0 or 1 but when
it is null, I get a grayed out checkbox that is checked. I want the null
values to display nothing - like with the null text in a textbox. How can I
accomplish that?

TIA

Wayne

============= Code to define column ==================
' Define Wait Column

Dim objWaitCol As New DataGridBoolColumn

objWaitCol.MappingName = "Wait"

objWaitCol.HeaderText = "Wait"

objWaitCol.Width = 50

objWaitCol.Alignment = HorizontalAlignment.Center

objWaitCol.NullText = ""

'Add the column to the styles

objRegsDataGridTableStyle.GridColumnStyles.Add(objWaitCol)
 
K

Ken Tucker [MVP]

Hi,


Go through the data and change any nulls to false.


Dim conn As SqlConnection

Dim strConn As String

Dim strSQL As String

Dim da As SqlDataAdapter





strConn = "Server = (local);"

strConn &= "Database = NorthWind;"

strConn &= "Integrated Security = SSPI;"



conn = New SqlConnection(strConn)

da = New SqlDataAdapter("Select * From Products", conn)

da.Fill(ds, "Products")

Dim dr As DataRow

For Each dr In ds.Tables("Products").Rows

If dr.IsNull("Discontinued") Then

dr.BeginEdit()

dr.Item("Discontinued") = False

dr.EndEdit()

End If

Next



Ken

----------------

I have a datagrid bound to dataset where some entries are null. In that grid
I am defining a column as Boolean (see code below) and I get the expected
checkbox which is checked or unchecked when the DB value is 0 or 1 but when
it is null, I get a grayed out checkbox that is checked. I want the null
values to display nothing - like with the null text in a textbox. How can I
accomplish that?

TIA

Wayne

============= Code to define column ==================
' Define Wait Column

Dim objWaitCol As New DataGridBoolColumn

objWaitCol.MappingName = "Wait"

objWaitCol.HeaderText = "Wait"

objWaitCol.Width = 50

objWaitCol.Alignment = HorizontalAlignment.Center

objWaitCol.NullText = ""

'Add the column to the styles

objRegsDataGridTableStyle.GridColumnStyles.Add(objWaitCol)
 
K

Ken Tucker [MVP]

Hi,

Another method. I created a new datagridboolcolumn which
automatically converts nulls to false. Use this in your tablestyle instead
of the datagridboolcolumn.

Public Class NoNullBoolColumn

Inherits DataGridBoolColumn

Protected Overrides Function GetColumnValueAtRow(ByVal lm As
System.Windows.Forms.CurrencyManager, ByVal row As Integer) As Object

Dim objNull As Object = Convert.DBNull

If objNull.Equals(MyBase.GetColumnValueAtRow(lm, row)) Then

Return False

Else

Return MyBase.GetColumnValueAtRow(lm, row)

End If

End Function

End Class



Ken

-----------------------

Hi,


Go through the data and change any nulls to false.


Dim conn As SqlConnection

Dim strConn As String

Dim strSQL As String

Dim da As SqlDataAdapter





strConn = "Server = (local);"

strConn &= "Database = NorthWind;"

strConn &= "Integrated Security = SSPI;"



conn = New SqlConnection(strConn)

da = New SqlDataAdapter("Select * From Products", conn)

da.Fill(ds, "Products")

Dim dr As DataRow

For Each dr In ds.Tables("Products").Rows

If dr.IsNull("Discontinued") Then

dr.BeginEdit()

dr.Item("Discontinued") = False

dr.EndEdit()

End If

Next



Ken

----------------

I have a datagrid bound to dataset where some entries are null. In that grid
I am defining a column as Boolean (see code below) and I get the expected
checkbox which is checked or unchecked when the DB value is 0 or 1 but when
it is null, I get a grayed out checkbox that is checked. I want the null
values to display nothing - like with the null text in a textbox. How can I
accomplish that?

TIA

Wayne

============= Code to define column ==================
' Define Wait Column

Dim objWaitCol As New DataGridBoolColumn

objWaitCol.MappingName = "Wait"

objWaitCol.HeaderText = "Wait"

objWaitCol.Width = 50

objWaitCol.Alignment = HorizontalAlignment.Center

objWaitCol.NullText = ""

'Add the column to the styles

objRegsDataGridTableStyle.GridColumnStyles.Add(objWaitCol)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top