By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,344 Members | 1,147 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,344 IT Pros & Developers. It's quick & easy.

Hide Boolean Col in DataGrid

P: n/a
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(obj WaitCol)
Nov 20 '05 #1
Share this Question
Share on Google+
4 Replies


P: n/a
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

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

"Wayne Wengert" <wa***************@wengert.com> wrote in message
news:ul**************@TK2MSFTNGP10.phx.gbl...
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(obj WaitCol)

Nov 20 '05 #2

P: n/a
Thanks for the reply Ken. I'll give that a try.

Wayne

"Ken Tucker [MVP]" <vb***@bellsouth.net> wrote in message
news:uM*************@TK2MSFTNGP10.phx.gbl...
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

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

"Wayne Wengert" <wa***************@wengert.com> wrote in message
news:ul**************@TK2MSFTNGP10.phx.gbl...
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(obj WaitCol)

Nov 20 '05 #3

P: n/a
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

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

"Ken Tucker [MVP]" <vb***@bellsouth.net> wrote in message
news:uM*************@TK2MSFTNGP10.phx.gbl...
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

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

"Wayne Wengert" <wa***************@wengert.com> wrote in message
news:ul**************@TK2MSFTNGP10.phx.gbl...
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(obj WaitCol)


Nov 20 '05 #4

P: n/a
Thanks - I'll try that out!

Wayne

"Ken Tucker [MVP]" <vb***@bellsouth.net> wrote in message
news:et*************@tk2msftngp13.phx.gbl...
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

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

"Ken Tucker [MVP]" <vb***@bellsouth.net> wrote in message
news:uM*************@TK2MSFTNGP10.phx.gbl...
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

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

"Wayne Wengert" <wa***************@wengert.com> wrote in message
news:ul**************@TK2MSFTNGP10.phx.gbl...
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(obj WaitCol)

Nov 20 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.