如何更新列表框中的数据并在VB的列表框中显示更新的数据? [英] How to update data from list box and displaying the updated data in the list box in VB?

查看:250
本文介绍了如何更新列表框中的数据并在VB的列表框中显示更新的数据?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

该表单允许我注册客户并将其相关详细信息保存到文本文件中,一旦我保存客户,我将此信息显示在列表框中。我的主要目的是能够修改相对于我已经保存的客户的信息,因此当我从列表框中选择一个客户的数据时,这些详细信息被放入编号的文本框中(txtBox1用于客户名称,txtBox2用于客户)出生日期)。我尝试在(btnUpdate_Click)中使用下面的代码只更改修改过的数据部分,避免重复,但似乎不起作用,是否有人有任何建议?谢谢。



我尝试了什么:



 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)然后
strAmendedRecord + = txtBoxN.Text& (,)
结束如果

下一个
MsgBox(strAmendedRecord)

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



Dim data As String =
每个项目在ListBox1.Items
data& = item.ToString()& vbNewLine

下一步

解决方案

您有两个不同的问题:



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 ... :(


这篇关于如何更新列表框中的数据并在VB的列表框中显示更新的数据?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆