Navigate through a dataset

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Peter Newman

    #1

    Navigate through a dataset

    i have a dataset and want to step thrpugh each row each time a user clicks a
    button,
  • Mrozu

    #2
    Re: Navigate through a dataset


    Peter Newman napisal(a):[color=blue]
    > i have a dataset and want to step thrpugh each row each time a user clicks a
    > button,[/color]

    and do what?

    For each row as new datarow in dataset1.tables (x).rows

    next

    Comment

    • Peter Newman

      #3
      Re: Navigate through a dataset


      basicly im displaying the data in text boxes, and need to allow the
      operators to navigate thro the records
      "Mrozu" wrote:
      [color=blue]
      >
      > Peter Newman napisal(a):[color=green]
      > > i have a dataset and want to step thrpugh each row each time a user clicks a
      > > button,[/color]
      >
      > and do what?
      >
      > For each row as new datarow in dataset1.tables (x).rows
      >
      > next
      >
      >[/color]

      Comment

      • Rich

        #4
        Re: Navigate through a dataset

        You can use a CurrencyManager object and Databinding for navigating and
        connecting the data to the textboxes. Here is how you do it:

        Dim cmgr as currencyManager '--form level

        Private Sub Form_Load(...)
        ....
        cmgr = CType(Me.Bindin gContext(datase t1.Tables("your tbl")), CurrencyManager )
        cmgr.Position = 0 '--initialize position of currencymanager

        '--then bind the textboxes - say you have 5 textboxes
        Me.txt1.DataBin dings.Add("Text ", dataset1.Tables ("yourtbl"), "fld1")
        Me.txt2.DataBin dings.Add("Text ", dataset1.Tables ("yourtbl"), "fld2")
        Me.txt3.DataBin dings.Add("Text ", dataset1.Tables ("yourtbl"), "fld3")
        Me.txt4.DataBin dings.Add("Text ", dataset1.Tables ("yourtbl"), "fld4")
        Me.txt5.DataBin dings.Add("Text ", dataset1.Tables ("yourtbl"), "fld5")
        ....
        End Sub

        Then you can have a button where you increment the currencymanager like this:

        Private Sub btn1_Click(...)
        cmgr += 1 '--navigate forward
        End Sub

        Private Sub btn2_Click(...)
        cmgr -= 1 '--navigate backward
        End Sub

        You bind the data from the dataset table to the textboxes. Just make sure
        that dataset1.Tables ("yourtbl") contains the fields that you specify in the
        databinding

        '----------------------------------------------------------------field/column name here
        Me.txt1.DataBin dings.Add("Text ", dataset1.Tables ("yourtbl"), "fld1")

        If the binding isn't working, you can loop through all the columns in your
        datatable (dataset1.Table s("yourtbl") ) like this:

        For each dc As DataColumn In dataset1.Tables ("yourtbl").Col umns
        Console.Write(d c.ColumnName & ", ")
        Next

        Look at the output window to see what columns (fields) your datatable
        contains. These are the names you have to use in the Databinding of the
        textboxes.

        HTH
        Rich


        "Peter Newman" wrote:
        [color=blue]
        >
        > basicly im displaying the data in text boxes, and need to allow the
        > operators to navigate thro the records
        > "Mrozu" wrote:
        >[color=green]
        > >
        > > Peter Newman napisal(a):[color=darkred]
        > > > i have a dataset and want to step thrpugh each row each time a user clicks a
        > > > button,[/color]
        > >
        > > and do what?
        > >
        > > For each row as new datarow in dataset1.tables (x).rows
        > >
        > > next
        > >
        > >[/color][/color]

        Comment

        • Cor Ligthert [MVP]

          #5
          Re: Navigate through a dataset

          Peter,

          Have a look at that currencymanager .position in this sample. You can set
          that to any value as long as it is inside the range 0 and table.row.count -
          1



          I hope this helps,

          Cor

          "Peter Newman" <PeterNewman@di scussions.micro soft.com> schreef in bericht
          news:82A6B3B8-264F-4D4D-8F8C-24D64135C4E4@mi crosoft.com...[color=blue]
          >
          > basicly im displaying the data in text boxes, and need to allow the
          > operators to navigate thro the records
          > "Mrozu" wrote:
          >[color=green]
          >>
          >> Peter Newman napisal(a):[color=darkred]
          >> > i have a dataset and want to step thrpugh each row each time a user
          >> > clicks a
          >> > button,[/color]
          >>
          >> and do what?
          >>
          >> For each row as new datarow in dataset1.tables (x).rows
          >>
          >> next
          >>
          >>[/color][/color]


          Comment

          Working...