简体   繁体   English

通过另一种形式更新文本文件中的一行

[英]Update a line in a text file from another form

I have a form that has MenuScripts (top-levels and second-levels). 我有一个包含MenuScripts的form (顶级和第二级)。

The problem that I am having is one of the second-levels is "Add" which brings you to another form . 我遇到的问题是第二层次之一,就是“添加”,它使您进入另一种form This form has a button 'Record' and textboxes . form具有“记录”按钮和textboxes This form allows the user to input data and when the record button is clicked, the inputted data is written to a text file. 该表格允许用户输入数据,并且当单击记录按钮时,输入的数据将被写入文本文件。

Back to the first form. 回到第一种形式。 Another second-level MenuScript is "Update" which brings the user to the same form as "Add"; 另一个第二级MenuScript是“更新”,它使用户具有与“添加”相同的form but first, the user has to click an item within a listbox to proceed. 但首先,用户必须单击listbox的一项才能继续。

How do I get the data from the selected item to appear in the appropriate textboxes and how do I get the 'Record' button to update data instead of thinking it is only an add-data button? 如何从所选项目中获取数据以出现在适当的textboxes如何获取“记录”按钮来更新数据,而不是认为它只是添加数据按钮?

Also, if someone can give me some pointers on making sure the user selects an item within the listbox would definitely be a plus! 另外,如果有人可以给我一些指示,以确保用户在listbox选择一个项目,那肯定是加分的!

Unfortunately, I cannot add images since my reputation is too low. 不幸的是,我的信誉太低,无法添加图像。

Here is a visual representation of my ultimate goal 这是我最终目标的直观表示

To access the control in another form, you could prefix the formname to the control name(name of the control in the other form). 要以另一种形式访问控件,可以在表单名称前添加控件名称(另一种形式的控件名称)。

Example: 例:

Form2.TextBox1.Text = "Hey, this is the second form"

To check whether an item is selected, you could do this way: 要检查是否选择了一个项目,您可以这样做:

    If ListBox1.SelectedItems.Count = 0 Then
        MessageBox.Show("Please select an item")
    Else
        MessageBox.Show("Thanks for selecting an item")
    End If

Or, this way: 或者,这样:

    If ListBox1.SelectedIndex = -1 Then
        MessageBox.Show("Please select an item")
    Else
        MessageBox.Show("Thanks for selecting an item")
    End If

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM