Link to home
Start Free TrialLog in
Avatar of dgb
dgb

asked on

mogrid1, how can I select the next/previous row in mogrid1 by clicking on an arrow

Hello,

Ik have an mogrid1 in a form and I want by clicking on a button go to the next row.
How can I do this.

thanks.
Avatar of VBRocks
VBRocks
Flag of United States of America image

Hello dgb,

Windows or ASP?

Regards,

VBRocks
dgb,

Here's a Windows example using the DataGridView:

        With Me.DataGridView1
            If .CurrentRow.Index < .Rows.Count Then _
                .CurrentCell = .Rows(.CurrentRow.Index + 1).Cells(0)
        End With

VBRocks
dgb,

On other note, if you use a BindingSource as the DataSource for the grid then, that's alternative approach, and it's very easy:

        If Me.DataGridView1.CurrentRow.Index < Me.DataGridView1.RowCount Then
            Dim bs As BindingSource = Me.DataGridView1.DataSource
            bs.Position += 1
        End If


VBRocks
Avatar of dgb
dgb

ASKER

hello,

I am not using a BindingSource for the grid. The following code shows the intention of how it has to work. In the gridrow that has been selected after using this code I want to gain the value of a cell, but the problem is that I do not click in the grid, I want the value of the cell of another row based on the code.

        Select Case Button
            Case "first"
               MoGrid1.Rows(0).Selected = True
            Case "last"
               MoGrid1.Rows(Grid1Count).Selected = True
               nRijindex = MoGrid1.CurrentRow.Index
            Case "next"
            Case "previous"
               MoGrid1.Rows.GetLastRow(MoGrid1.CurrentRow.Index)
         End Select


ASKER CERTIFIED SOLUTION
Avatar of VBRocks
VBRocks
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of dgb

ASKER

thank you, exactly what I was looking for.