Visual Basic.NET - Botones de desplazamiento por DataGridview

 
Vista:
sin imagen de perfil
Val: 344
Bronce
Ha mantenido su posición en Visual Basic.NET (en relación al último mes)
Gráfica de Visual Basic.NET

Botones de desplazamiento por DataGridview

Publicado por Miguel (281 intervenciones) el 22/11/2013 17:41:33
Hola, quería haber si alguno me puede ayudar con este código. Tengo el problema de que no consigo desplazarme por el DataGridView.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
Option Explicit On
Imports System.Data.OleDb
Imports System.ComponentModel
 
Public Class frmCp
    Inherits System.Windows.Forms.Form
    Private cn As New OleDbConnection
    Private da As New OleDbDataAdapter
    Private ds As New DataSet
    Private dt As New DataTable
    Private fila As Integer
 
    Private Sub frmCp_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        conectaBD()
        cargaDatos()
        DataGridView1.DataSource = ds.Tables("CargaCp")
        Dim X As Boolean
        Me.btnDcha.Enabled = X
    End Sub
 
    Sub conectaBD()
        Try
            cn = New OleDbConnection
            cn.ConnectionString = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=c:\Cantabrico\gpCantabrico\gpCantabrico\calderas.accdb"
            cn.Open()
        Catch ex As Exception
            MessageBox.Show(ex.Message)
        End Try
    End Sub
 
  Private Sub btnPrimero_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnPrimero.Click
        Try
            fila = 0
            cargaDatos()
            Me.DataGridView1.BindingContext(ds, "cargaCp").Position = 0    'No funciona
        Catch ex As Exception
            MessageBox.Show(ex.Message)
        End Try
    End Sub
 
    Private Sub btnAnterior_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnAnterior.Click
        Try
            If fila = 0 Then
                MsgBox("Ha llegado al priner registro", MsgBoxStyle.Critical, "Error")
            Else
                fila -= 1
                cargaDatos()
                                                      ' Aqui he probado de cincuenta formas sin conseguir nada
            End If
        Catch ex As Exception
            MessageBox.Show(ex.Message)
        End Try
    End Sub

Gracias y un saludo
Valora esta pregunta
Me gusta: Está pregunta es útil y esta claraNo me gusta: Está pregunta no esta clara o no es útil
0
Responder