Vous êtes sur la page 1sur 6

ANOTACIONES VARIOS

CodigoProg.VB
=============
Class Cliente
' cdigo de la clase
' ............
' ............
End Class

Module General
' cdigo del mdulo
' ............
' ............
End Module

Class Facturas
' cdigo de la clase
' ............
' ............
End Class

CodigoClases.VB
=============
Class Cliente
' cdigo de la clase
' ............
' ............
End Class

Class Facturas
' cdigo de la clase
' ............
' ............
End Class

**************************************************
RutinasVarias.VB
================
Module General
' cdigo del mdulo
' ............
' ............
End Module

Module Listados
' cdigo del mdulo
' ............
' ............
End Module


PROCEDIMIENTOS

Sub Prueba()
' instruccin1
' instruccin2
' instruccin3
' ............
' ............
' ............
' instruccinN
End Sub

COMENTARIOS: Los comentarios van con comilla simple Alt + 39 ( ' )

Pintar filas de un datagridview segun una condicin.
Hola gente, estoy tratando de hacer un aplicacion de alertas de vencimientos, en
donde es muy simple, yo tengo la aplicacion principal para cargar datos etc. Entonces
hice una pequea aplicacin que lo que hace es conectarse a la misma base de datos
que la principal y solo desplega un datagridview y solo me trae aquellos registros que
se han pasado la fecha de vencimiento o q faltan 30 dias para su vencimiento. Hasta
ahi perfecto. El problema es cuando quiero pintar cada fila de acuerdo a si se vencio o
esta por vencer (rojo para uno, amarillo para el otro) El codigo que encotnre en
internet y utilice fue el siguiente pero no me funciona, la aplicacion arranca perfecto
pero nunca pinta las filas.

Dim row As DataGridViewRow
Dim fechaActual As DateTime = Date.Now

For Each row In DataGridView1.Rows
Select Case fechaActual
Case Is > row.Cells("FechaVencimiento").Value
row.DefaultCellStyle.BackColor = Color.LightYellow
Case Is < row.Cells("FechaVencimiento").Value
row.DefaultCellStyle.BackColor = Color.DarkRed
Case Else
row.DefaultCellStyle.BackColor = Color.White
End Select
Next

Tambien probe con un if dentro del for each
If row.cells("FechaVencimiento").value > fechaActual then
row.DefaultCellStyle.BackColor = Color.LightYellow
else
ow.DefaultCellStyle.BackColor = Color.DarkRed



Para desplazarse en un datagrid con botones de avanzar y retroceder .

Cuando dices "desplazarme por los registros" te refieres a seleccionar
la fila en el DataGrid?
Si es asi, puedes adaptar este codigo...

'En tu boton para avanzar
If (dgClient.CurrentRowIndex + 1) <dgClient.VisibleRowCount Then
dgClient.Select(dgClient.CurrentRowIndex + 1)
End If

'En tu boton para retroceder
If (dgClient.CurrentRowIndex - 1) >dgClient.VisibleRowCount Then
dgClient.Select(dgClient.CurrentRowIndex - 1)
End If

Saludos...











Option Explicit On
Option Strict On

' Espacios de nombres
' '''''''''''''''''''''''''''''''''''''''''
Imports System.Data.SqlClient

Public Class Form1

'BindingSource
Private WithEvents bs As New BindingSource

' Adaptador de datos sql
Private SqlDataAdapter As SqlDataAdapter

' Cadena de conexin
Private Const cs As String = "Data Source=(local)\SQLEXPRESS;" & _
"Initial Catalog=demo_bd;" & _
"Integrated Security=true"

' flag
Private bEdit As Boolean


' actualizar los cambios al salir
' ''''''''''''''''''''''''''''''''''''''''
Private Sub Form1_FormClosing( _
ByVal sender As Object, _
ByVal e As System.Windows.Forms.FormClosingEventArgs) _
Handles Me.FormClosing

If bEdit Then
'preguntar si se desea guardar
If (MsgBox( _
"Guardar cambios ?", _
MsgBoxStyle.YesNo, _
"guardar")) = MsgBoxResult.Yes Then

Actualizar(False)
End If
End If
End Sub

Private Sub Form1_Load( _
ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles MyBase.Load

' propiedades del datagrid
' '''''''''''''''''''''''''''''''''''''
With DataGridView1
' alternar color de filas
.AlternatingRowsDefaultCellStyle.BackColor = Color.FloralWhite
.DefaultCellStyle.BackColor = Color.Beige
' Establecer el origen de datos para el DataGridview
.DataSource = bs
End With

' botones
' '''''''''''''''''''''''''''''''''''''
btn_Update.Text = "Guardar cambios"
btn_delete.Text = "Eliminar registro"
btn_new.Text = "Nuevo"

btn_first.Text = "<<"
btn_Previous.Text = "<"
btn_next.Text = ">"
btn_last.Text = ">>"

' cagar los datos
cargar_registros("Select * From alumnos Order by Apellido",
DataGridView1)

End Sub

Private Sub cargar_registros( _
ByVal sql As String, _
ByVal dv As DataGridView)

Try
' Inicializar el SqlDataAdapter indicandole el comando y el
connection string
SqlDataAdapter = New SqlDataAdapter(sql, cs)

Dim SqlCommandBuilder As New SqlCommandBuilder(SqlDataAdapter)

' llenar el DataTable
Dim dt As New DataTable()
SqlDataAdapter.Fill(dt)

' Enlazar el BindingSource con el datatable anterior
' ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
bs.DataSource = dt

With dv
.Refresh()
' coloca el registro arriba de todo
.FirstDisplayedScrollingRowIndex = bs.Position
End With

bEdit = False

Catch exSql As SqlException
MsgBox(exSql.Message.ToString)
Catch ex As Exception
MsgBox(ex.Message.ToString)
End Try
End Sub

' botn para guardar los cambios y llenar la grilla
Private Sub Button1_Click( _
ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles btn_Update.Click

Actualizar()

End Sub


' Eliminar el elemento actual del BindingSource y actualizar
Private Sub btn_delete_Click( _
ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles btn_delete.Click

If Not bs.Current Is Nothing Then
' eliminar
bs.RemoveCurrent()

'Guardar los cambios y recargar
Actualizar()
Else
MsgBox("No hay un registro actual para eliminar", _
MsgBoxStyle.Exclamation, _
"Eliminar")
End If


End Sub

Private Sub Actualizar(Optional ByVal bCargar As Boolean = True)
' Actualizar y guardar cambios

If Not bs.DataSource Is Nothing Then
SqlDataAdapter.Update(CType(bs.DataSource, DataTable))
If bCargar Then
cargar_registros("Select * From alumnos Order by Apellido",
DataGridView1)
End If
End If
End Sub

Private Sub btn_first_Click( _
ByVal sender As System.Object, _
ByVal e As System.EventArgs) _
Handles btn_first.Click, btn_last.Click, btn_next.Click,
btn_Previous.Click

' Botones para moverse por los registros
' '''''''''''''''''''''''''''''''''''''''''''''

If sender Is btn_Previous Then
bs.MovePrevious()
ElseIf sender Is btn_first Then
bs.MoveFirst()
ElseIf sender Is btn_next Then
bs.MoveNext()
ElseIf sender Is btn_last Then
bs.MoveLast()
End If

End Sub

Private Sub DataGridView1_CellEndEdit( _
ByVal sender As Object, _
ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) _
Handles DataGridView1.CellEndEdit

bEdit = True
End Sub

' nuevo registro
Private Sub btn_new_Click( _
ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles btn_new.Click

bs.AddNew()

End Sub
End Class










NO PERMITE NUMEROS, LETRAS EN CUADRO DE TEXTO.

1.- Buscar el evento keypress del Texbox.

Solo acepta nmeros
Private Sub txt_usuario_KeyPress(sender As Object, e As KeyPressEventArgs)
Handles txt_usuario.KeyPress
If Char.IsDigit(e.KeyChar) Then
e.Handled = False
ElseIf Char.IsControl(e.KeyChar) Then
e.Handled = False
Else
e.Handled = True
End If
End Sub

Solo acepta letras

Private Sub txt_usuario_KeyPress(sender As Object, e As KeyPressEventArgs)
Handles txt_usuario.KeyPress
If Char.IsLetter(e.KeyChar) Then
e.Handled = False
ElseIf Char.IsControl(e.KeyChar) Then
e.Handled = False
Else
e.Handled = True
End If
End Sub

Vous aimerez peut-être aussi