根据文本框中的特定值移至下一条记录

时间:2019-04-01 15:49:23

标签: vb.net

我需要一些帮助。我希望能够通过动态方式使用表单上的下一个和上一个按钮浏览记录 值。

我目前拥有的代码将从起始值移至下一条记录,但是例如,如果我键入100,我希望能够从特定值开始 进入文本框,然后单击下一步,每次单击应显示101、102等记录。

我该如何做到这一点。非常感谢

这是我目前的当前代码。

Dim intcurrentindex As Integer = 0
If intcurrentindex < ds.Tables(0).Rows.Count - 1 Then
    intcurrentindex = intcurrentindex - 1

    TextBox1.Text = ds.Tables(0).Rows(intcurrentindex).Item("NAME").ToString
    TextBox2.Text = ds.Tables(0).Rows(intcurrentindex).Item("CODE").ToString
    TextBox3.Text = ds2.Tables(0).Rows(intcurrentindex).Item("STOCKNAME").ToString
    TextBox4.Text = ds.Tables(0).Rows(intcurrentindex).Item("WEIGHT").ToString
    TextBox5.Text = ds.Tables(0).Rows(intcurrentindex).Item("LOCATION").ToString

End If

2 个答案:

答案 0 :(得分:0)

也许是这样的:

Public Class Form1

Private intcurrentindex As Integer = 0
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
    TxtCurrentIndex.Text = 0
End Sub

Private Sub BtnNext_Click(sender As Object, e As EventArgs) Handles BtnNext.Click

    If TxtCurrentIndex.Text = "" Then
        intcurrentindex = 0
    Else
        'set intcurrentindex to textbox value
        intcurrentindex = TxtCurrentIndex.text
    End If

    If intcurrentindex < ds.Tables(0).Rows.Count - 1 Then
        TextBox1.Text = ds.Tables(0).Rows(intcurrentindex).Item("NAME").ToString
        TextBox2.Text = ds.Tables(0).Rows(intcurrentindex).Item("CODE").ToString
        TextBox3.Text = ds2.Tables(0).Rows(intcurrentindex).Item("STOCKNAME").ToString
        TextBox4.Text = ds.Tables(0).Rows(intcurrentindex).Item("WEIGHT").ToString
        TextBox5.Text = ds.Tables(0).Rows(intcurrentindex).Item("LOCATION").ToString
        intcurrentindex = intcurrentindex + 1
    End If
End Sub

Private Sub BtnPrevius_Click(sender As Object, e As EventArgs) Handles BtnPrevius.Click

    If TxtCurrentIndex.Text = "" Then
        intcurrentindex = 0
    Else
        'set intcurrentindex to textbox value
        intcurrentindex = TxtCurrentIndex.text
    End If


    If intcurrentindex > 0 Then
        TextBox1.Text = ds.Tables(0).Rows(intcurrentindex).Item("NAME").ToString
        TextBox2.Text = ds.Tables(0).Rows(intcurrentindex).Item("CODE").ToString
        TextBox3.Text = ds2.Tables(0).Rows(intcurrentindex).Item("STOCKNAME").ToString
        TextBox4.Text = ds.Tables(0).Rows(intcurrentindex).Item("WEIGHT").ToString
        TextBox5.Text = ds.Tables(0).Rows(intcurrentindex).Item("LOCATION").ToString
        intcurrentindex = intcurrentindex - 1
    End If
End Sub

结束班级

您需要一个变量来存储当前索引

答案 1 :(得分:0)

谢谢你们在此方面的帮助。最后,我使用了绑定源使其工作。