开发者

How do I make a column invisible in a gridview?

开发者 https://www.devze.com 2022-12-24 20:28 出处:网络
How do I make a column invisible in a gridview? I tried to use this: dataGridView.Columns(0).Visib开发者_Python百科le = False

How do I make a column invisible in a gridview? I tried to use this:

dataGridView.Columns(0).Visib开发者_Python百科le = False

But its getting an error "Index was out of range. Must be non-negative and less than the size of the collection. Parameter name: index". How can I do this?


Finally, I got the answer. Using this we can make a column invisible:

Private Sub dataGridView_RowDataBound( _
   ByVal sender As Object, _
   ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs _
) Handles dataGridView.RowDataBound
   If e.Row.RowType = DataControlRowType.DataRow OrElse _
      e.Row.RowType = DataControlRowType.Header OrElse _
      e.Row.RowType = DataControlRowType.Footer _
   Then
      e.Row.Cells(1).Visible = False
   End If
End Sub


I can not understand why is not working with you.

Its working just find on me - at least on c#.

Check to see what is going wrong, maybe you call it before the DataGrid is rendered/created or something like that.


Your statement "dataGridView.Columns(0).Visible = False" was ok, you just need to fix the index. The Columns and Cell indexes are base 1, not base 0.

If you want to make invisible the first column use:

dataGridView.Columns(1).Visible = False

That works for me.

0

精彩评论

暂无评论...
验证码 换一张
取 消