Can I hide the data of a column?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • meomap0z1
    New Member
    • Jan 2020
    • 9

    Can I hide the data of a column?

    I have this table of data. Now I wanna hide the data of the "Password" column. How can I do that?. Many thanks
    Attached Files
  • SioSio
    Contributor
    • Dec 2019
    • 272

    #2
    Here's an easy way to just hide the display.
    This is VB.net code.
    Code:
        ''' <summary>Set password cell Number</summary> 
        Private Function IsPasswordCell(ByVal row As Integer, ByVal column As Integer) As Boolean
            Return column = 2
        End Function
        ''' <summary> Returns True if password cell</summary> 
        Private Function IsPasswordCell(ByVal address As Point) As Boolean
            Return IsPasswordCell(address.Y, address.X)
        End Function
    	
    	Private Sub DataGridView1_CellFormatting(ByVal sender As Object, ByVal e As _
          DataGridViewCellFormattingEventArgs) Handles DataGridView1.CellFormatting
            If IsPasswordCell(e.RowIndex, e.ColumnIndex) Then
                'Mask password 
                e.Value = StrDup(Len(e.Value), "*"c)
            End If
        End Sub

    Comment

    • lewish95
      New Member
      • Mar 2020
      • 33

      #3
      If you want to hide an entire row or column, right-click on the row or column header and then choose Hide. To hide a row or multiple rows, you need to right-click on the row number at the far left. To hide a column or multiple columns, you need to right-click on the column letter at the very top.

      Comment

      • tmudgal16
        New Member
        • Feb 2023
        • 10

        #4
        You can only hide full columns. If you are hiding the data in the table is important, then the data below needs to be moved to a different sheet. Or, if it only needs to be hidden when printed, then you can change the font color to match the background color.

        Comment

        • Vanisha
          New Member
          • Jan 2023
          • 26

          #5
          Yes, you can hide data of a column in a database, spreadsheet, or table by making the column's width smaller, by setting the font color to match the background, or by using a formula to display an empty string.

          However, keep in mind that hiding data in this manner doesn't actually make the data secure, as it can still be accessed by someone with the right knowledge and tools. If you need to protect sensitive information, you should consider using encryption or other security measures.

          Comment

          • danp129
            Recognized Expert Contributor
            • Jul 2006
            • 323

            #6
            If you were binding to an object of List<User> you could add the [Browsable(false )] attribute to the Password property. Alternatively you could do this:

            Code:
                    private void FillGrid()
                    {
                        DataGridView1.DataSource = YourDataSource;
                        var passCol = DataGridView1.Columns["Password"];
                        if(passCol != null )
                        {
                            DataGridView1.Columns[passCol.Index].Visible = false;
                        }
                    }

            Comment

            Working...