且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何更新列表框中的数据并在VB的列表框中显示更新的数据?

更新时间:2023-11-28 20:05:28

您有两个不同的问题:



1st:

如果你想在你的List中输入一个新客户,你可以将数据输入到文本框中。

之后你应该有一个Button必须将此数据保存到您的文件中并修改您的列表框。

也许您还应检查文件中是否仍存在新输入的数据。



第二名:

您选择一个列表框条目。在这种情况下,您将获得Listbox-Event SelectedIndexChanged。根据此事件,您可以从文件中加载相关数据并将其显示在文本框中。



我在您的代码片段中找不到任何内容...: (

The form allows me to register customers and save their relevant details into a text file, once I save customers I display this information into a list box. My main aim is now to be able to amend information relative to a customer I have already saved therefore when I select one customer's data from the list box these details are put into numbered text boxes (txtBox1 which is for the customer name and txtBox2 for customer date of birth). I have tried using the code below in (btnUpdate_Click) to only change the parts of data that are amended and avoiding any repetition but it does not seem to work, does anyone got any suggestions? Thank you.

What I have tried:

Dim strAmendedRecord As String = ""
        For N As Integer = 1 To 5
            Dim txtBoxN As TextBox = Me.Controls.Find("txtBox" & N, True).FirstOrDefault
            If Not IsNothing(txtBoxN) Then
                strAmendedRecord += txtBoxN.Text & (",")
            End If

        Next
        MsgBox(strAmendedRecord)
       
        ListBox1.SelectedIndex = ListBox1.SelectedIndex - 1
        ListBox1.Items.RemoveAt(ListBox1.SelectedIndex - 1)
        ListBox1.Items.Add(ListBox1.SelectedIndex + 1)



        Dim data As String = ""
        For Each item In ListBox1.Items
            data &= item.ToString() & vbNewLine

        Next

You have 2 different problems :

1st:
If you want to enter a new customer to your List you enter your data into the textboxes.
After that you should have a Button which either must save this data to your file and also modify your Listbox.
Perhaps you should also check if the "new" entered data is still existing inside your file.

2nd:
You select one of your Listbox-entries. In this case you get the Listbox-Event SelectedIndexChanged. Depending on this Event you load the relevant data from your file and display it in your textboxes.

Nothing of this I can find in your code-snippet ... :(