Visual Basic.NET - ¿Como recorro un datagrid?

 
Vista:

¿Como recorro un datagrid?

Publicado por HAF (178 intervenciones) el 10/10/2006 13:43:18
Hola amigos del foro, tengo un datagrid enlazado a una base de datos de acces a traves de un dataset.
¿como puedo recorrer los valores del datagrid?

La conexion es :

conn.ConnectionString = funciones.conexion_ACCESS
adaptador = New OleDbDataAdapter("SELECT * FROM inventario", conn)
comando = New OleDbCommandBuilder(adaptador)
datos = New DataSet
conn.Open()
adaptador.Fill(datos, "inventariol")
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

RE:¿Como recorro un datagrid?

Publicado por Harold (411 intervenciones) el 10/10/2006 14:12:28
''''''''''''''''''''''''
Este sencillo ejemplo recorre todas las cedas del datagrid y extrae los datos y los muestra para imprimir.

Necesitas estos controles
PrintDocument,PrintPreviewDialog

'Propiedad
printpreviewdialog1.document=printdocument1

'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Imports System.Drawing
Imports vb = Microsoft.VisualBasic

Private printFont As Font
Dim ncadena As String
Dim count As Integer = 0

'Esto rellena con espacios en blanco de acuerdo al num de caracteres por columna
Sub RellenarEsp(ByVal str As String, ByVal columna As Int32)
Dim r As Int32
Dim cad As String = ""
Dim digito As Int32
ncadena = ""
Dim numcif As Int32 = str.Length

Select Case columna ' Espacios de las columnas
Case 1 : digito = 8 'Codigo Articulo
Case 2 : digito = 35 'nombreArticulo
Case 4 : digito = 15 'Lote
Case 8 : digito = 20 'Estante
Case 9 : digito = 3 'Ubicacion de larticulo
End Select
If numcif > digito Then
ncadena = Mid(str, 1, digito)
Else
For r = 1 To (digito - numcif)
cad = " "
ncadena = ncadena & cad
Next
ncadena = str & ncadena
End If

End Sub

Private Sub PrintDocument1_PrintPage(ByVal sender As Object, ByVal e As System.Drawing.Printing.PrintPageEventArgs) Handles PrintDocument1.PrintPage
Dim linesPerPage As Single = 0
Dim yPos As Single = 0
Dim leftMargin As Single = 30 'e.MarginBounds.Left
Dim topMargin As Single = e.MarginBounds.Top - 50
Dim line As String = Nothing
linesPerPage = e.MarginBounds.Height / printFont.GetHeight(e.Graphics)

Dim Fil, Col As Int32
Dim LString As String = ""
LString = LString & "Documento interno del almacén " & vbCrLf & vbCrLf & vbCrLf & vbCrLf
LString = LString & " UBICACIONES DE LOTES (PREPARACION DE PEDIDOS) " & vbCrLf & vbCrLf & vbCrLf & vbCrLf
LString = LString & "Pedido de Venta:" & txtIdPedido.Text & " Fecha:" & Today & vbCrLf & vbCrLf & vbCrLf
LString = LString & "Cant CodArt Articulo Lote Estante Posición" & vbCrLf & _
"------------------------------------------------------------------------------------------------" & vbCrLf & vbCrLf
count = 0
For Fil = 0 To dgvCargando.Rows.Count - 1
For Col = 0 To dgvCargando.Columns.Count - 1
If Col = 3 Or Col = 5 Or Col = 6 Or Col = 7 Then
GoTo sig
Else
Call RellenarEsp(dgvCargando.Item(Col, Fil).Value.ToString, Col)
If Col < 9 Then
LString = LString & ncadena & Space(1)
Else
LString = LString & ncadena & vbCrLf
End If
End If
sig:
Next
count += 1
Next
yPos = topMargin + (count * printFont.GetHeight(e.Graphics))
e.Graphics.DrawString(LString, printFont, Brushes.Black, leftMargin, yPos, New StringFormat())
If Not (line Is Nothing) Then
e.HasMorePages = True
Else
e.HasMorePages = False
End If
End Sub

Private Sub lnkPrint_LinkClicked(ByVal sender As System.Object, ByVal e As System.Windows.Forms.LinkLabelLinkClickedEventArgs) Handles lnkPrint.LinkClicked
If dgvCargando.Rows.Count > 0 Then
Try
printFont = New Font("Courier new", 9)
'PrintDocument1.Print()
PrintPreviewDialog1.Width = 600
PrintPreviewDialog1.ShowDialog()
Catch ex As Exception
MessageBox.Show(ex.Message)
End Try
End If
End Sub
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar