Hide Boolean Col in DataGrid

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Wayne  Wengert

    Hide Boolean Col in DataGrid

    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 DataGridBoolCol umn

    objWaitCol.Mapp ingName = "Wait"

    objWaitCol.Head erText = "Wait"

    objWaitCol.Widt h = 50

    objWaitCol.Alig nment = HorizontalAlign ment.Center

    objWaitCol.Null Text = ""

    'Add the column to the styles

    objRegsDataGrid TableStyle.Grid ColumnStyles.Ad d(objWaitCol)


  • Ken Tucker [MVP]

    #2
    Re: Hide Boolean Col in DataGrid

    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(s trConn)

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

    da.Fill(ds, "Products")

    Dim dr As DataRow

    For Each dr In ds.Tables("Prod ucts").Rows

    If dr.IsNull("Disc ontinued") Then

    dr.BeginEdit()

    dr.Item("Discon tinued") = False

    dr.EndEdit()

    End If

    Next



    Ken

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

    "Wayne Wengert" <wayneDONTWANTS PAM@wengert.com > wrote in message
    news:ulIEsiOeEH A.3520@TK2MSFTN GP10.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 DataGridBoolCol umn

    objWaitCol.Mapp ingName = "Wait"

    objWaitCol.Head erText = "Wait"

    objWaitCol.Widt h = 50

    objWaitCol.Alig nment = HorizontalAlign ment.Center

    objWaitCol.Null Text = ""

    'Add the column to the styles

    objRegsDataGrid TableStyle.Grid ColumnStyles.Ad d(objWaitCol)



    Comment

    • Wayne  Wengert

      #3
      Re: Hide Boolean Col in DataGrid

      Thanks for the reply Ken. I'll give that a try.

      Wayne

      "Ken Tucker [MVP]" <vb2ae@bellsout h.net> wrote in message
      news:uMvGEcVeEH A.384@TK2MSFTNG P10.phx.gbl...[color=blue]
      > 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(s trConn)
      >
      > da = New SqlDataAdapter( "Select * From Products", conn)
      >
      > da.Fill(ds, "Products")
      >
      > Dim dr As DataRow
      >
      > For Each dr In ds.Tables("Prod ucts").Rows
      >
      > If dr.IsNull("Disc ontinued") Then
      >
      > dr.BeginEdit()
      >
      > dr.Item("Discon tinued") = False
      >
      > dr.EndEdit()
      >
      > End If
      >
      > Next
      >
      >
      >
      > Ken
      >
      > ----------------
      >
      > "Wayne Wengert" <wayneDONTWANTS PAM@wengert.com > wrote in message
      > news:ulIEsiOeEH A.3520@TK2MSFTN GP10.phx.gbl...
      > I have a datagrid bound to dataset where some entries are null. In that[/color]
      grid[color=blue]
      > 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[/color]
      when[color=blue]
      > 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[/color]
      I[color=blue]
      > accomplish that?
      >
      > TIA
      >
      > Wayne
      >
      > ============= Code to define column =============== ===
      > ' Define Wait Column
      >
      > Dim objWaitCol As New DataGridBoolCol umn
      >
      > objWaitCol.Mapp ingName = "Wait"
      >
      > objWaitCol.Head erText = "Wait"
      >
      > objWaitCol.Widt h = 50
      >
      > objWaitCol.Alig nment = HorizontalAlign ment.Center
      >
      > objWaitCol.Null Text = ""
      >
      > 'Add the column to the styles
      >
      > objRegsDataGrid TableStyle.Grid ColumnStyles.Ad d(objWaitCol)
      >
      >
      >[/color]


      Comment

      • Ken Tucker [MVP]

        #4
        Re: Hide Boolean Col in DataGrid

        Hi,

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

        Public Class NoNullBoolColum n

        Inherits DataGridBoolCol umn

        Protected Overrides Function GetColumnValueA tRow(ByVal lm As
        System.Windows. Forms.CurrencyM anager, ByVal row As Integer) As Object

        Dim objNull As Object = Convert.DBNull

        If objNull.Equals( MyBase.GetColum nValueAtRow(lm, row)) Then

        Return False

        Else

        Return MyBase.GetColum nValueAtRow(lm, row)

        End If

        End Function

        End Class



        Ken

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

        "Ken Tucker [MVP]" <vb2ae@bellsout h.net> wrote in message
        news:uMvGEcVeEH A.384@TK2MSFTNG P10.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(s trConn)

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

        da.Fill(ds, "Products")

        Dim dr As DataRow

        For Each dr In ds.Tables("Prod ucts").Rows

        If dr.IsNull("Disc ontinued") Then

        dr.BeginEdit()

        dr.Item("Discon tinued") = False

        dr.EndEdit()

        End If

        Next



        Ken

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

        "Wayne Wengert" <wayneDONTWANTS PAM@wengert.com > wrote in message
        news:ulIEsiOeEH A.3520@TK2MSFTN GP10.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 DataGridBoolCol umn

        objWaitCol.Mapp ingName = "Wait"

        objWaitCol.Head erText = "Wait"

        objWaitCol.Widt h = 50

        objWaitCol.Alig nment = HorizontalAlign ment.Center

        objWaitCol.Null Text = ""

        'Add the column to the styles

        objRegsDataGrid TableStyle.Grid ColumnStyles.Ad d(objWaitCol)




        Comment

        • Wayne  Wengert

          #5
          Re: Hide Boolean Col in DataGrid

          Thanks - I'll try that out!

          Wayne

          "Ken Tucker [MVP]" <vb2ae@bellsout h.net> wrote in message
          news:etaJ5xWeEH A.556@tk2msftng p13.phx.gbl...[color=blue]
          > Hi,
          >
          > Another method. I created a new datagridboolcol umn which
          > automatically converts nulls to false. Use this in your tablestyle[/color]
          instead[color=blue]
          > of the datagridboolcol umn.
          >
          > Public Class NoNullBoolColum n
          >
          > Inherits DataGridBoolCol umn
          >
          > Protected Overrides Function GetColumnValueA tRow(ByVal lm As
          > System.Windows. Forms.CurrencyM anager, ByVal row As Integer) As Object
          >
          > Dim objNull As Object = Convert.DBNull
          >
          > If objNull.Equals( MyBase.GetColum nValueAtRow(lm, row)) Then
          >
          > Return False
          >
          > Else
          >
          > Return MyBase.GetColum nValueAtRow(lm, row)
          >
          > End If
          >
          > End Function
          >
          > End Class
          >
          >
          >
          > Ken
          >
          > -----------------------
          >
          > "Ken Tucker [MVP]" <vb2ae@bellsout h.net> wrote in message
          > news:uMvGEcVeEH A.384@TK2MSFTNG P10.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(s trConn)
          >
          > da = New SqlDataAdapter( "Select * From Products", conn)
          >
          > da.Fill(ds, "Products")
          >
          > Dim dr As DataRow
          >
          > For Each dr In ds.Tables("Prod ucts").Rows
          >
          > If dr.IsNull("Disc ontinued") Then
          >
          > dr.BeginEdit()
          >
          > dr.Item("Discon tinued") = False
          >
          > dr.EndEdit()
          >
          > End If
          >
          > Next
          >
          >
          >
          > Ken
          >
          > ----------------
          >
          > "Wayne Wengert" <wayneDONTWANTS PAM@wengert.com > wrote in message
          > news:ulIEsiOeEH A.3520@TK2MSFTN GP10.phx.gbl...
          > I have a datagrid bound to dataset where some entries are null. In that[/color]
          grid[color=blue]
          > 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[/color]
          when[color=blue]
          > 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[/color]
          I[color=blue]
          > accomplish that?
          >
          > TIA
          >
          > Wayne
          >
          > ============= Code to define column =============== ===
          > ' Define Wait Column
          >
          > Dim objWaitCol As New DataGridBoolCol umn
          >
          > objWaitCol.Mapp ingName = "Wait"
          >
          > objWaitCol.Head erText = "Wait"
          >
          > objWaitCol.Widt h = 50
          >
          > objWaitCol.Alig nment = HorizontalAlign ment.Center
          >
          > objWaitCol.Null Text = ""
          >
          > 'Add the column to the styles
          >
          > objRegsDataGrid TableStyle.Grid ColumnStyles.Ad d(objWaitCol)
          >
          >
          >
          >[/color]


          Comment

          Working...