所以我可以使用以下内容填充我在Visual Studio中使用的组合框,以及我想要的所有结果:
Dim pnum As New List(Of String)
For Each polnumber As InsuredDataSet.Claims_InsuredRow In Me.InsuredDataSet.Claims_Insured
pnum.Add(polnumber.Policy_Number)
Next
pnum.Reverse()
Me.Policy_NumberComboBox.DataSource = pnum
真棒。现在我想通过获取表单上 Insured_NameTextBox 的输入/选择内容来限制 pnum ,并仅返回带有匹配的Insured_Name的Policy_Number。我认为这可以使用If语句执行,但我尝试的所有内容(stringcompare,InsuredName_TextBox = Me.InsuredDataSet.ClaimsInsured等)要么不限制结果,要么完全限制结果,以便不显示任何内容。知道在哪里放置If语句和应该比较什么?
更新: 我认为有一些混乱所以我将下面的整个加载子包括在内:
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
'TODO: This line of code loads data into the 'IncidentsDataSet.Claims_Incidents' table. You can move, or remove it, as needed.
Me.Claims_IncidentsTableAdapter.Fill(Me.IncidentsDataSet.Claims_Incidents)
'TODO: This line of code loads data into the 'InsuredDataSet.Claims_Insured' table. You can move, or remove it, as needed.
Me.Claims_InsuredTableAdapter.Fill(Me.InsuredDataSet.Claims_Insured)
'textbox autocomplete mode
Dim Iname As New AutoCompleteStringCollection()
For Each insname As InsuredDataSet.Claims_InsuredRow In Me.InsuredDataSet.Claims_Insured
Iname.Add(insname.Insured_Name)
Next
Me.Insured_NameTextBox.AutoCompleteCustomSource = Iname
'combobox autocomplete code (now sorting by last included!)
Dim pnum As New List(Of String)
For Each polnumber As InsuredDataSet.Claims_InsuredRow In Me.InsuredDataSet.Claims_Insured
pnum.Add(polnumber.Policy_Number)
Next
pnum.Reverse()
Me.Policy_NumberComboBox.DataSource = pnum
End Sub
答案 0 :(得分:2)
尝试这样的事情:
Me.Policy_NumberComboBox.DataSource = InsuredDataSet.Claims_Insured.Where(Function(r) r.Insured_Name = Insured_NameTextBox.Text).Select(Function(r) r.Policy_Number).Reverse()
我们越来越近了。根据您的问题的更新,您在表单加载时运行此代码。但是,在表单加载时,您的文本框将始终为空。当文本框中的值发生更改时,您将如何处理以重新过滤数据?
答案 1 :(得分:1)
这是C#
Me.InsuredDataSet.Claims_Insured.Where(x => x.Insured_Name == Insured_NameTextBox.Text);