Data grid problem

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • charvi
    New Member
    • May 2007
    • 121

    Data grid problem

    Hi
    I have a datagrid in my form where it is used to viw the contents of table hich has 10 fields.
    now i want some columns of datagrid to be visible as false
    in vb we code it has
    datagrid1.colum ns(1).visible =false
    how to code it in vb,.net 2003
    can anyone help
  • shweta123
    Recognized Expert Contributor
    • Nov 2006
    • 692

    #2
    Hi,

    You can use this code for making some coumns invisible in datagrid :
    Code:
        Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
            Dim ts As New DataGridTableStyle
            ''Name of the table to be mapped from dataset
            ts.MappingName = "table"
            DataGrid1.TableStyles.Add(ts)
    
            Dim myTableStyle As DataGridTableStyle = DataGrid1.TableStyles(0)
            Dim mycolumns As GridColumnStylesCollection
    
            ' Get the GridColumnStylesCollection of Data Grid.
            mycolumns = myTableStyle.GridColumnStyles
            Dim i As Integer
    
            ' Remove the CustName ColumnStyle from the data grid.
            If mycolumns.Contains("columnName") Then
                Dim myDataColumnStyle As DataGridColumnStyle = mycolumns("columnName")
                i = mycolumns.IndexOf(myDataColumnStyle)
                mycolumns.RemoveAt(i)
            End If
        End Sub 'RemoveColumnStyle_Clicked
    Originally posted by charvi
    Hi
    I have a datagrid in my form where it is used to viw the contents of table hich has 10 fields.
    now i want some columns of datagrid to be visible as false
    in vb we code it has
    datagrid1.colum ns(1).visible =false
    how to code it in vb,.net 2003
    can anyone help

    Comment

    • charvi
      New Member
      • May 2007
      • 121

      #3
      Originally posted by shweta123
      Hi,

      You can use this code for making some coumns invisible in datagrid :
      Code:
          Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
              Dim ts As New DataGridTableStyle
              ''Name of the table to be mapped from dataset
              ts.MappingName = "table"
              DataGrid1.TableStyles.Add(ts)
      
              Dim myTableStyle As DataGridTableStyle = DataGrid1.TableStyles(0)
              Dim mycolumns As GridColumnStylesCollection
      
              ' Get the GridColumnStylesCollection of Data Grid.
              mycolumns = myTableStyle.GridColumnStyles
              Dim i As Integer
      
              ' Remove the CustName ColumnStyle from the data grid.
              If mycolumns.Contains("columnName") Then
                  Dim myDataColumnStyle As DataGridColumnStyle = mycolumns("columnName")
                  i = mycolumns.IndexOf(myDataColumnStyle)
                  mycolumns.RemoveAt(i)
              End If
          End Sub 'RemoveColumnStyle_Clicked




      Hi
      i used this code but my problem is not solved
      can any one suggest how to make some column of datagrid in vb.net in visible at form load

      Comment

      • charvi
        New Member
        • May 2007
        • 121

        #4
        Hi
        i used this code but my problem is not solved
        can any one suggest how to make some column of datagrid in vb.net in visible at form load

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

        Comment

        • shweta123
          Recognized Expert Contributor
          • Nov 2006
          • 692

          #5
          Hi,

          What error are you getting? Can you post all your code so that we can help you?

          Comment

          Working...