-1

因此,我可以使用以下所有结果填充我在 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
4

2 回答 2

2

尝试这样的事情:

Me.Policy_NumberComboBox.DataSource = InsuredDataSet.Claims_Insured.Where(Function(r) r.Insured_Name = Insured_NameTextBox.Text).Select(Function(r) r.Policy_Number).Reverse()

我们越来越近了。根据对您问题的更新,您在表单加载时运行此代码。但是,在表单加载时,您的文本框将始终为空。当文本框中的值发生变化时,您会怎么做以重新过滤您的数据?

于 2013-09-11T16:00:13.010 回答
1

这是 C#

Me.InsuredDataSet.Claims_Insured.Where(x => x.Insured_Name == Insured_NameTextBox.Text);
于 2013-09-11T16:01:49.863 回答