【发布时间】:2021-05-16 15:19:11
【问题描述】:
对于我的课程作业,我正在使用 Visual Basic 制作一个预订系统,该系统还存储有关未付款项的数据,我使用列表框显示保存在数组中的注册客户的姓名,使用列表框项的索引结合数组的主键,例如:
数组:
| User ID | Amount Owed |
|---|---|
| 0 | 100 |
| 1 | 0 |
| 2 | 200 |
然后将其添加到列表框中,姓名和联系信息等客户数据存储在发票数据的单独数组中,通过用户 ID 作为主键链接。
列表框:
| Index | Name |
|---|---|
| 0 | John Doe |
| 1 | Jane Doe |
| 2 | Joe Bloggs |
这个系统一切正常,直到我想添加一个复选框来过滤掉没有未付款项的人 过滤列表框:
| Index | Name | User ID |
|---|---|---|
| 0 | John Doe | 0 |
| 1 | Joe Bloggs | 2 |
如您所见,列表框的索引现在不再与用户 ID 相同,这反过来又破坏了我涉及使用 .SelectedIndex 函数的其他操作。
这是这个过程涉及的代码
Private Sub SortOpenInvoice_CheckedChanged(sender as Object, e as EventArgs) _
Handles CheckBox1.CheckedChanged
Dim HasOpenInvoice As Boolean
HasOpenInvoice = False
If SortOpenInvoice.Checked = True Then
For i = 0 To numofCustomers - 1
For j = 0 To numofInvoices - 1
If invoices(j).AmountOwed > 0 And invoices(j).CustomerID = customers(i).CustomerID Then 'Searches for an open invoice (outstanding payment) linked to a customers ID
HasOpenInvoice = True 'Flag for if there is an open invoice (outstanding payment)
End If
Next
If HasOpenInvoice = False Then
lbxMemberList.Items.RemoveAt(Convert.ToInt32(customers(i).CustomerID)) 'Removes index if no open invoice is found
Else
HasOpenInvoice = False
End If
Next
...
End Sub
在过滤掉特定字段后,我可以做些什么来保留索引值?或者您有没有其他可以建议的替代解决方案?
谢谢!
【问题讨论】: