我使用combobox来过滤一个gridview,gridview过滤发生了,但是当我想在gridview中输入一个数据时,如果一个网格还有一条线(数据),一个消息错误显示,所以我不能输入一个数据,否则当网格没有任何数据时,我可以输入一个值
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
gridview在加载表单上填充
Private 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
我回应我自己
我认为问题是关于过滤我添加删除过滤器,所以它是更好的,我现在可以输入数据,但网格工作不正确!显示一个和唯一的线
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