Results 1 to 6 of 6

Thread: [RESOLVED] how to hide unbounded columns in a datagrid

  1. #1

    Thread Starter
    Fanatic Member VBKNIGHT's Avatar
    Join Date
    Oct 2000
    Location
    Port25
    Posts
    619

    Resolved [RESOLVED] how to hide unbounded columns in a datagrid

    guys how can i hide unbounded columns in a datagrid? TIA

    If a post has helped you then Please Rate it!

  2. #2
    Lively Member AjayKumar's Avatar
    Join Date
    Nov 2003
    Location
    Noida
    Posts
    94

    Talking Re: how to hide unbounded columns in a datagrid

    Private Sub ingrid_ItemDataBound(ByVal sender As System.Object, ByVal e As System.Web.UI.WebControls.DataGridItemEventArgs) Handles ingrid.ItemDataBound
    e.Item.Cells(7).Visible = False
    End

    or use this
    DataGrid1.Columns(1).Visible = Not (DataGrid1.Columns(1).Visible)
    I hope one of them will work well.
    Happy Programming
    HI ITs exciting!!!!!

  3. #3

    Thread Starter
    Fanatic Member VBKNIGHT's Avatar
    Join Date
    Oct 2000
    Location
    Port25
    Posts
    619

    Re: how to hide unbounded columns in a datagrid

    thanks for replying.

    Quote Originally Posted by AjayKumar
    Private Sub ingrid_ItemDataBound(ByVal sender As System.Object, ByVal e As System.Web.UI.WebControls.DataGridItemEventArgs) Handles ingrid.ItemDataBound
    e.Item.Cells(7).Visible = False
    End

    [this code will hide just the header item selected and not the entire column will result in unmatched header and row. ]


    or use this
    DataGrid1.Columns(1).Visible = Not (DataGrid1.Columns(1).Visible)
    [this code works only with bounded columns and will return index error if used. ]


    I hope one of them will work well.
    Happy Programming
    Last edited by VBKNIGHT; Oct 3rd, 2005 at 09:12 PM.

    If a post has helped you then Please Rate it!

  4. #4
    Lively Member AjayKumar's Avatar
    Join Date
    Nov 2003
    Location
    Noida
    Posts
    94

    Talking Re: how to hide unbounded columns in a datagrid

    Use visibility options in both of events

    Private Sub ingrid_ItemDataBound(ByVal sender As System.Object, ByVal e As System.Web.UI.WebControls.DataGridItemEventArgs) Handles ingrid.ItemDataBound
    e.Item.Cells(7).Visible = False
    Select Case e.Item.ItemType
    Case ListItemType.Header
    e.Item.Cells(7).Visible = False

    Case ListItemType.Item
    e.Item.Cells(7).Visible = False
    Case ListItemType.AlternatingItem
    e.Item.Cells(7).Visible = False

    End


    and in itemcreated event also

    Private Sub ingrid_ItemCreated(ByVal sender As System.Object, ByVal e As System.Web.UI.WebControls.DataGridItemEventArgs) Handles ingrid.ItemCreated

    Select Case e.Item.ItemType
    Case ListItemType.Header
    e.Item.Cells(7).Visible = False

    Case ListItemType.Item
    e.Item.Cells(7).Visible = False
    Case ListItemType.AlternatingItem
    e.Item.Cells(7).Visible = False
    End Select
    End Sub
    HI ITs exciting!!!!!

  5. #5

    Thread Starter
    Fanatic Member VBKNIGHT's Avatar
    Join Date
    Oct 2000
    Location
    Port25
    Posts
    619

    Re: how to hide unbounded columns in a datagrid

    thanks! this is what i need.

    If a post has helped you then Please Rate it!

  6. #6
    Super Moderator Wokawidget's Avatar
    Join Date
    Nov 2001
    Location
    Headingly Occupation: Classified
    Posts
    9,632

    Re: how to hide unbounded columns in a datagrid

    VB Code:
    1. Select Case e.Item.ItemType
    2.    Case ListItemType.Header
    3.       e.Item.Cells(7).Visible = False
    4.    Case ListItemType.Item
    5.       e.Item.Cells(7).Visible = False
    6.    Case ListItemType.AlternatingItem
    7.       e.Item.Cells(7).Visible = False
    8. End Select
    That can be replaced with:
    VB Code:
    1. e.Item.Cells(7).Visible = False
    Alternatively, if you only want to show the bound columns, then do:
    VB Code:
    1. MyDataGrid.AutoGenerateColumns = False
    Then regardless of how many columns there are in the datasource, only the bound columns you set up get shown.

    Woka

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width