我使用组合框过滤网格视图,发生网格视图过滤,但是当我想在网格视图中输入数据时,如果网格还有一行(数据),则显示消息错误,因此我无法输入数据,否则当网格没有任何数据时,我可以输入一个值
gridview后面的表格有一个自动生成的字段
Private Sub Le_clientComboBox_SelectedIndexChanged(sender As Object, e As EventArgs) Handles Le_clientComboBox.SelectedIndexChanged Try Me.DevisBindingSource.Filter = "Code_client = '" & Le_clientComboBox.SelectedValue & "'" Catch ex As Exception MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error) Finally If con.State = ConnectionState.Open Then con.Close() End If End Try End Sub
在加载表单
上填充gridviewPrivate Sub frmDevis_Load(sender As Object, e As EventArgs) Handles MyBase.Load
'TODO: cette ligne de code charge les données dans la table 'Tassaruf_tijariDataSet_Devis.Devis'. Vous pouvez la déplacer ou la supprimer selon vos besoins.
Me.DevisTableAdapter.Fill(Me.Tassaruf_tijariDataSet_Devis.Devis)
Catch ex As Exception
MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
Finally
If con.State = ConnectionState.Open Then
con.Close()
End If
End Try
End Sub
答案 0 :(得分:0)
我回应自己
我认为问题在于过滤 我添加删除过滤器,所以它更好,我现在可以输入数据,但网格不能正常工作!显示一行唯一行
Private Sub Le_clientComboBox_SelectedIndexChanged(sender As Object, e As EventArgs) Handles Le_clientComboBox.SelectedIndexChanged
Try
Me.DevisBindingSource.RemoveFilter()
Me.DevisBindingSource.Filter = "Code_client = '" & Le_clientComboBox.SelectedValue & "'"
Catch ex As Exception
MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
Finally
If con.State = ConnectionState.Open Then
con.Close()
End If
End Try
End Sub