在文本框空白处,我想清除我的gridview源
但是我无法在vb.net中这样做。
在参考几个答案后,我尝试了不成功的尝试:
grdUsers.rows.clear()
:不适用于vb.net
grdUsers.DataSource=""
grdUsers.columns.clear()
但它没有成功。
请帮我清除gridview的数据源。
答案 0 :(得分:6)
如果您的DataGridView绑定到DataSource并且您想要清除它,那么您可以使用Nothing
关键字后跟DataBind()
。
grdUsers.DataSource = Nothing
grdUsers.DataBind()
这是more information on the DataBind() method。
如果要在TextBox1中文本为空时清除行,则应为文本框创建TextChanged事件...
Private Sub TextBox1_TextChanged(sender As Object, e As System.EventArgs) Handles TextBox1.TextChanged
If TextBox1.Text.Trim = "" Then
grdUsers.DataSource = Nothing
grdUsers.DataBind()
End If
End Sub