如何使一个列在GridView中不可见?我试图用这个:如何在GridView中使列不可见?
dataGridView.Columns(0).Visible = False
但它得到一个错误"Index was out of range. Must be non-negative and less than the size of the collection. Parameter name: index"
。我怎样才能做到这一点?
如何使一个列在GridView中不可见?我试图用这个:如何在GridView中使列不可见?
dataGridView.Columns(0).Visible = False
但它得到一个错误"Index was out of range. Must be non-negative and less than the size of the collection. Parameter name: index"
。我怎样才能做到这一点?
最后,我得到了答案。使用这个我们可以使一列不可见:
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
我不明白为什么不与你合作。
它的工作只是找到我 - 至少在c#上。
检查看看哪里出了问题,也许你在DataGrid呈现/创建之前或之前调用它。
您的语句“dataGridView.Columns(0).Visible = False”没问题,您只需修复索引即可。列和细胞指数为基础1,不垒0
如果你想看不见的第一列使用:
dataGridView.Columns(1)。可见=假
这对我的作品。
AutoGenerateColumns是否设置为true?我认为自动生成的列不包含在Columns集合中。 – rodrigocl 2012-01-05 13:54:16