' LEER UN ARCHIVO DE DATOS EN FORMATO XML
' MOSTRARLO EN UN DATAGRID PERSONALIZADO
' LAS CAJAS DE TEXTO CON LOS TELÉFONOS SÓLO ACEPTAN NÚMEROS
'
' FORMULARIO PRINCIPAL: Datagrid.vb
' --------------------------------------
'Espacios de nombres necesarios
Imports Microsoft.VisualBasic
Imports System
Imports System.Data
Imports System.Data.OleDb
Imports System.ComponentModel
Imports System.Drawing
Imports System.IO
'Espacio de nombre propio de la aplicación, al pertenecer a este espacio
'de nombres las 2 clases del ejercicio (Datagrid y DataGridDigitsTextBoxColumn)
'hay herencia entre ellas y podemos usar la clase DataGridDigitsTextBoxColumn
'dentro de esta clase DataGrid
Namespace DataGridNumbersOnly
Public Class Datagrid
Inherits System.Windows.Forms.Form
'Variables declaradas a nivel de clase para poder usarlas desde
'cualquier procedimiento o función
Private datos As DataSet 'DataSet: conjunto de datos desconectados
Private ruta As String 'almacena la ruta a la base de datos
Private abierto As Boolean = False 'para saber si ya está abierta la base de datos
Private cambios As Boolean = False 'para saber si hay cambios pendientes de guardar
#Region " Código generado por el Diseñador de Windows Forms "
Public Sub New()
MyBase.New()
'El Diseñador de Windows Forms requiere esta llamada.
InitializeComponent()
'Agregar cualquier inicialización después de la llamada a InitializeComponent()
End Sub
'Form reemplaza a Dispose para limpiar la lista de componentes.
Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
If disposing Then
If Not (components Is Nothing) Then
components.Dispose()
End If
End If
MyBase.Dispose(disposing)
End Sub
'Requerido por el Diseñador de Windows Forms
Private components As System.ComponentModel.IContainer
'NOTA: el Diseñador de Windows Forms requiere el siguiente procedimiento
'Puede modificarse utilizando el Diseñador de Windows Forms.
'No lo modifique con el editor de código.
Friend WithEvents btSalir As System.Windows.Forms.Button
Friend WithEvents btActualizar As System.Windows.Forms.Button
Friend WithEvents btCargar As System.Windows.Forms.Button
Friend WithEvents dlgFile As System.Windows.Forms.OpenFileDialog
Friend WithEvents Grid As System.Windows.Forms.DataGrid
Friend WithEvents GroupBox1 As System.Windows.Forms.GroupBox
Friend WithEvents GroupBox2 As System.Windows.Forms.GroupBox
Friend WithEvents Label2 As System.Windows.Forms.Label
Friend WithEvents ToolTip1 As System.Windows.Forms.ToolTip
Friend WithEvents GroupBox3 As System.Windows.Forms.GroupBox
Friend WithEvents Label3 As System.Windows.Forms.Label
Friend WithEvents btFiltrar As System.Windows.Forms.Button
Friend WithEvents Panel1 As System.Windows.Forms.Panel
Friend WithEvents txFiltro As System.Windows.Forms.TextBox
Friend WithEvents btQuitar As System.Windows.Forms.Button
Friend WithEvents A As System.Windows.Forms.Button
Friend WithEvents B As System.Windows.Forms.Button
Friend WithEvents C As System.Windows.Forms.Button
Friend WithEvents D As System.Windows.Forms.Button
Friend WithEvents E As System.Windows.Forms.Button
Friend WithEvents F As System.Windows.Forms.Button
Friend WithEvents G As System.Windows.Forms.Button
Friend WithEvents H As System.Windows.Forms.Button
Friend WithEvents I As System.Windows.Forms.Button
Friend WithEvents J As System.Windows.Forms.Button
Friend WithEvents K As System.Windows.Forms.Button
Friend WithEvents L As System.Windows.Forms.Button
Friend WithEvents M As System.Windows.Forms.Button
Friend WithEvents N As System.Windows.Forms.Button
Friend WithEvents O As System.Windows.Forms.Button
Friend WithEvents P As System.Windows.Forms.Button
Friend WithEvents Q As System.Windows.Forms.Button
Friend WithEvents R As System.Windows.Forms.Button
Friend WithEvents S As System.Windows.Forms.Button
Friend WithEvents T As System.Windows.Forms.Button
Friend WithEvents U As System.Windows.Forms.Button
Friend WithEvents V As System.Windows.Forms.Button
Friend WithEvents Y As System.Windows.Forms.Button
Friend WithEvents Z As System.Windows.Forms.Button
Friend WithEvents GroupBox5 As System.Windows.Forms.GroupBox
Friend WithEvents PictureBox1 As System.Windows.Forms.PictureBox
Friend WithEvents GroupBox4 As System.Windows.Forms.GroupBox
<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
Me.components = New System.ComponentModel.Container
Dim resources As System.Resources.ResourceManager = New System.Resources.ResourceManager(GetType(DataGrid))
Me.btSalir = New System.Windows.Forms.Button
Me.btActualizar = New System.Windows.Forms.Button
Me.btCargar = New System.Windows.Forms.Button
Me.dlgFile = New System.Windows.Forms.OpenFileDialog
Me.Grid = New System.Windows.Forms.DataGrid
Me.GroupBox1 = New System.Windows.Forms.GroupBox
Me.Label2 = New System.Windows.Forms.Label
Me.GroupBox2 = New System.Windows.Forms.GroupBox
Me.ToolTip1 = New System.Windows.Forms.ToolTip(Me.components)
Me.PictureBox1 = New System.Windows.Forms.PictureBox
Me.btFiltrar = New System.Windows.Forms.Button
Me.btQuitar = New System.Windows.Forms.Button
Me.GroupBox3 = New System.Windows.Forms.GroupBox
Me.txFiltro = New System.Windows.Forms.TextBox
Me.Label3 = New System.Windows.Forms.Label
Me.Panel1 = New System.Windows.Forms.Panel
Me.A = New System.Windows.Forms.Button
Me.B = New System.Windows.Forms.Button
Me.C = New System.Windows.Forms.Button
Me.D = New System.Windows.Forms.Button
Me.E = New System.Windows.Forms.Button
Me.F = New System.Windows.Forms.Button
Me.G = New System.Windows.Forms.Button
Me.H = New System.Windows.Forms.Button
Me.I = New System.Windows.Forms.Button
Me.J = New System.Windows.Forms.Button
Me.K = New System.Windows.Forms.Button
Me.L = New System.Windows.Forms.Button
Me.M = New System.Windows.Forms.Button
Me.N = New System.Windows.Forms.Button
Me.O = New System.Windows.Forms.Button
Me.P = New System.Windows.Forms.Button
Me.Q = New System.Windows.Forms.Button
Me.R = New System.Windows.Forms.Button
Me.S = New System.Windows.Forms.Button
Me.T = New System.Windows.Forms.Button
Me.U = New System.Windows.Forms.Button
Me.V = New System.Windows.Forms.Button
Me.Y = New System.Windows.Forms.Button
Me.Z = New System.Windows.Forms.Button
Me.GroupBox5 = New System.Windows.Forms.GroupBox
Me.GroupBox4 = New System.Windows.Forms.GroupBox
CType(Me.Grid, System.ComponentModel.ISupportInitialize).BeginInit()
Me.GroupBox1.SuspendLayout()
Me.GroupBox2.SuspendLayout()
Me.GroupBox3.SuspendLayout()
Me.SuspendLayout()
'
'btSalir
'
Me.btSalir.Anchor = CType((System.Windows.Forms.AnchorStyles.Bottom Or System.Windows.Forms.AnchorStyles.Left), System.Windows.Forms.AnchorStyles)
Me.btSalir.FlatStyle = System.Windows.Forms.FlatStyle.Popup
Me.btSalir.Font = New System.Drawing.Font("Verdana", 8.25!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
Me.btSalir.Location = New System.Drawing.Point(16, 40)
Me.btSalir.Name = "btSalir"
Me.btSalir.Size = New System.Drawing.Size(80, 24)
Me.btSalir.TabIndex = 26
Me.btSalir.Text = "Salir"
Me.ToolTip1.SetToolTip(Me.btSalir, "Salir del programa")
'
'btActualizar
'
Me.btActualizar.Anchor = CType((System.Windows.Forms.AnchorStyles.Bottom Or System.Windows.Forms.AnchorStyles.Left), System.Windows.Forms.AnchorStyles)
Me.btActualizar.Enabled = False
Me.btActualizar.FlatStyle = System.Windows.Forms.FlatStyle.Popup
Me.btActualizar.Font = New System.Drawing.Font("Verdana", 8.25!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
Me.btActualizar.Location = New System.Drawing.Point(216, 16)
Me.btActualizar.Name = "btActualizar"
Me.btActualizar.Size = New System.Drawing.Size(120, 24)
Me.btActualizar.TabIndex = 0
Me.btActualizar.TabStop = False
Me.btActualizar.Text = "Actualizar cambios"
'
'btCargar
'
Me.btCargar.Anchor = CType((System.Windows.Forms.AnchorStyles.Bottom Or System.Windows.Forms.AnchorStyles.Left), System.Windows.Forms.AnchorStyles)
Me.btCargar.FlatStyle = System.Windows.Forms.FlatStyle.Popup
Me.btCargar.Font = New System.Drawing.Font("Verdana", 8.25!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
Me.btCargar.Location = New System.Drawing.Point(24, 352)
Me.btCargar.Name = "btCargar"
Me.btCargar.Size = New System.Drawing.Size(184, 24)
Me.btCargar.TabIndex = 0
Me.btCargar.Text = "Conectar con archivo XML "
'
'Grid
'
Me.Grid.Anchor = CType((((System.Windows.Forms.AnchorStyles.Top Or System.Windows.Forms.AnchorStyles.Bottom) _
Or System.Windows.Forms.AnchorStyles.Left) _
Or System.Windows.Forms.AnchorStyles.Right), System.Windows.Forms.AnchorStyles)
Me.Grid.CaptionFont = New System.Drawing.Font("Verdana", 9.75!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
Me.Grid.DataMember = ""
Me.Grid.Font = New System.Drawing.Font("Verdana", 9.75!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
Me.Grid.HeaderFont = New System.Drawing.Font("Verdana", 9.75!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
Me.Grid.HeaderForeColor = System.Drawing.SystemColors.ControlText
Me.Grid.Location = New System.Drawing.Point(8, 8)
Me.Grid.Name = "Grid"
Me.Grid.Size = New System.Drawing.Size(600, 296)
Me.Grid.TabIndex = 1
'
'GroupBox1
'
Me.GroupBox1.Anchor = CType((System.Windows.Forms.AnchorStyles.Bottom Or System.Windows.Forms.AnchorStyles.Left), System.Windows.Forms.AnchorStyles)
Me.GroupBox1.Controls.Add(Me.btActualizar)
Me.GroupBox1.Location = New System.Drawing.Point(8, 336)
Me.GroupBox1.Name = "GroupBox1"
Me.GroupBox1.Size = New System.Drawing.Size(352, 56)
Me.GroupBox1.TabIndex = 27
Me.GroupBox1.TabStop = False
'
'Label2
'
Me.Label2.Anchor = CType((System.Windows.Forms.AnchorStyles.Bottom Or System.Windows.Forms.AnchorStyles.Left), System.Windows.Forms.AnchorStyles)
Me.Label2.Font = New System.Drawing.Font("Verdana", 8.25!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
Me.Label2.Location = New System.Drawing.Point(200, 64)
Me.Label2.Name = "Label2"
Me.Label2.Size = New System.Drawing.Size(224, 16)
Me.Label2.TabIndex = 5
Me.Label2.TextAlign = System.Drawing.ContentAlignment.MiddleCenter
'
'GroupBox2
'
Me.GroupBox2.Anchor = CType((System.Windows.Forms.AnchorStyles.Bottom Or System.Windows.Forms.AnchorStyles.Left), System.Windows.Forms.AnchorStyles)
Me.GroupBox2.Controls.Add(Me.btSalir)
Me.GroupBox2.Location = New System.Drawing.Point(464, 408)
Me.GroupBox2.Name = "GroupBox2"
Me.GroupBox2.Size = New System.Drawing.Size(112, 96)
Me.GroupBox2.TabIndex = 28
Me.GroupBox2.TabStop = False
'
'ToolTip1
'
Me.ToolTip1.AutoPopDelay = 8000
Me.ToolTip1.InitialDelay = 500
Me.ToolTip1.ReshowDelay = 100
'
'PictureBox1
'
Me.PictureBox1.Anchor = CType(((System.Windows.Forms.AnchorStyles.Bottom Or System.Windows.Forms.AnchorStyles.Left) _
Or System.Windows.Forms.AnchorStyles.Right), System.Windows.Forms.AnchorStyles)
Me.PictureBox1.Image = CType(resources.GetObject("PictureBox1.Image"), System.Drawing.Image)
Me.PictureBox1.Location = New System.Drawing.Point(592, 336)
Me.PictureBox1.Name = "PictureBox1"
Me.PictureBox1.Size = New System.Drawing.Size(10, 152)
Me.PictureBox1.SizeMode = System.Windows.Forms.PictureBoxSizeMode.CenterImage
Me.PictureBox1.TabIndex = 0
Me.PictureBox1.TabStop = False
Me.ToolTip1.SetToolTip(Me.PictureBox1, "Emilio Pérez Egido")
Me.PictureBox1.Visible = False
'
'btFiltrar
'
Me.btFiltrar.Anchor = CType((System.Windows.Forms.AnchorStyles.Bottom Or System.Windows.Forms.AnchorStyles.Left), System.Windows.Forms.AnchorStyles)
Me.btFiltrar.Enabled = False
Me.btFiltrar.FlatStyle = System.Windows.Forms.FlatStyle.Popup
Me.btFiltrar.Font = New System.Drawing.Font("Verdana", 8.25!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
Me.btFiltrar.Location = New System.Drawing.Point(360, 16)
Me.btFiltrar.Name = "btFiltrar"
Me.btFiltrar.Size = New System.Drawing.Size(72, 24)
Me.btFiltrar.TabIndex = 1
Me.btFiltrar.TabStop = False
Me.btFiltrar.Text = "Filtrar"
'
'btQuitar
'
Me.btQuitar.Anchor = CType((System.Windows.Forms.AnchorStyles.Bottom Or System.Windows.Forms.AnchorStyles.Left), System.Windows.Forms.AnchorStyles)
Me.btQuitar.Enabled = False
Me.btQuitar.FlatStyle = System.Windows.Forms.FlatStyle.Popup
Me.btQuitar.Font = New System.Drawing.Font("Verdana", 8.25!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
Me.btQuitar.Location = New System.Drawing.Point(16, 56)
Me.btQuitar.Name = "btQuitar"
Me.btQuitar.Size = New System.Drawing.Size(160, 24)
Me.btQuitar.TabIndex = 2
Me.btQuitar.TabStop = False
Me.btQuitar.Text = "Quitar todos los filtros"
'
'GroupBox3
'
Me.GroupBox3.Anchor = CType((System.Windows.Forms.AnchorStyles.Bottom Or System.Windows.Forms.AnchorStyles.Left), System.Windows.Forms.AnchorStyles)
Me.GroupBox3.Controls.Add(Me.btQuitar)
Me.GroupBox3.Controls.Add(Me.btFiltrar)
Me.GroupBox3.Controls.Add(Me.txFiltro)
Me.GroupBox3.Controls.Add(Me.Label3)
Me.GroupBox3.Controls.Add(Me.Label2)
Me.GroupBox3.Controls.Add(Me.Panel1)
Me.GroupBox3.Location = New System.Drawing.Point(8, 400)
Me.GroupBox3.Name = "GroupBox3"
Me.GroupBox3.Size = New System.Drawing.Size(448, 104)
Me.GroupBox3.TabIndex = 29
Me.GroupBox3.TabStop = False
Me.GroupBox3.Text = "Filtrar registros"
'
'txFiltro
'
Me.txFiltro.Anchor = CType((System.Windows.Forms.AnchorStyles.Bottom Or System.Windows.Forms.AnchorStyles.Left), System.Windows.Forms.AnchorStyles)
Me.txFiltro.Font = New System.Drawing.Font("Verdana", 9.75!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
Me.txFiltro.Location = New System.Drawing.Point(144, 16)
Me.txFiltro.Name = "txFiltro"
Me.txFiltro.ReadOnly = True
Me.txFiltro.Size = New System.Drawing.Size(176, 23)
Me.txFiltro.TabIndex = 0
Me.txFiltro.Text = ""
'
'Label3
'
Me.Label3.Anchor = CType((System.Windows.Forms.AnchorStyles.Bottom Or System.Windows.Forms.AnchorStyles.Left), System.Windows.Forms.AnchorStyles)
Me.Label3.AutoSize = True
Me.Label3.Font = New System.Drawing.Font("Verdana", 8.25!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
Me.Label3.Location = New System.Drawing.Point(16, 24)
Me.Label3.Name = "Label3"
Me.Label3.Size = New System.Drawing.Size(113, 17)
Me.Label3.TabIndex = 3
Me.Label3.Text = "Filtrar por nombre:"
Me.Label3.TextAlign = System.Drawing.ContentAlignment.MiddleLeft
'
'Panel1
'
Me.Panel1.Anchor = CType((System.Windows.Forms.AnchorStyles.Bottom Or System.Windows.Forms.AnchorStyles.Left), System.Windows.Forms.AnchorStyles)
Me.Panel1.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D
Me.Panel1.Location = New System.Drawing.Point(192, 56)
Me.Panel1.Name = "Panel1"
Me.Panel1.Size = New System.Drawing.Size(240, 32)
Me.Panel1.TabIndex = 4
'
'A
'
Me.A.Anchor = CType((System.Windows.Forms.AnchorStyles.Bottom Or System.Windows.Forms.AnchorStyles.Left), System.Windows.Forms.AnchorStyles)
Me.A.FlatStyle = System.Windows.Forms.FlatStyle.Popup
Me.A.Font = New System.Drawing.Font("Verdana", 8.25!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
Me.A.Location = New System.Drawing.Point(8, 312)
Me.A.Name = "A"
Me.A.Size = New System.Drawing.Size(24, 23)
Me.A.TabIndex = 2
Me.A.TabStop = False
Me.A.Text = "A"
'
'B
'
Me.B.Anchor = CType((System.Windows.Forms.AnchorStyles.Bottom Or System.Windows.Forms.AnchorStyles.Left), System.Windows.Forms.AnchorStyles)
Me.B.FlatStyle = System.Windows.Forms.FlatStyle.Popup
Me.B.Font = New System.Drawing.Font("Verdana", 8.25!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
Me.B.Location = New System.Drawing.Point(40, 312)
Me.B.Name = "B"
Me.B.Size = New System.Drawing.Size(24, 23)
Me.B.TabIndex = 3
Me.B.TabStop = False
Me.B.Text = "B"
'
'C
'
Me.C.Anchor = CType((System.Windows.Forms.AnchorStyles.Bottom Or System.Windows.Forms.AnchorStyles.Left), System.Windows.Forms.AnchorStyles)
Me.C.FlatStyle = System.Windows.Forms.FlatStyle.Popup
Me.C.Font = New System.Drawing.Font("Verdana", 8.25!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
Me.C.Location = New System.Drawing.Point(72, 312)
Me.C.Name = "C"
Me.C.Size = New System.Drawing.Size(24, 23)
Me.C.TabIndex = 4
Me.C.TabStop = False
Me.C.Text = "C"
'
'D
'
Me.D.Anchor = CType((System.Windows.Forms.AnchorStyles.Bottom Or System.Windows.Forms.AnchorStyles.Left), System.Windows.Forms.AnchorStyles)
Me.D.FlatStyle = System.Windows.Forms.FlatStyle.Popup
Me.D.Font = New System.Drawing.Font("Verdana", 8.25!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
Me.D.Location = New System.Drawing.Point(104, 312)
Me.D.Name = "D"
Me.D.Size = New System.Drawing.Size(24, 23)
Me.D.TabIndex = 5
Me.D.TabStop = False
Me.D.Text = "D"
'
'E
'
Me.E.Anchor = CType((System.Windows.Forms.AnchorStyles.Bottom Or System.Windows.Forms.AnchorStyles.Left), System.Windows.Forms.AnchorStyles)
Me.E.FlatStyle = System.Windows.Forms.FlatStyle.Popup
Me.E.Font = New System.Drawing.Font("Verdana", 8.25!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
Me.E.Location = New System.Drawing.Point(136, 312)
Me.E.Name = "E"
Me.E.Size = New System.Drawing.Size(24, 23)
Me.E.TabIndex = 6
Me.E.TabStop = False
Me.E.Text = "E"
'
'F
'
Me.F.Anchor = CType((System.Windows.Forms.AnchorStyles.Bottom Or System.Windows.Forms.AnchorStyles.Left), System.Windows.Forms.AnchorStyles)
Me.F.FlatStyle = System.Windows.Forms.FlatStyle.Popup
Me.F.Font = New System.Drawing.Font("Verdana", 8.25!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
Me.F.Location = New System.Drawing.Point(168, 312)
Me.F.Name = "F"
Me.F.Size = New System.Drawing.Size(24, 23)
Me.F.TabIndex = 7
Me.F.TabStop = False
Me.F.Text = "F"
'
'G
'
Me.G.Anchor = CType((System.Windows.Forms.AnchorStyles.Bottom Or System.Windows.Forms.AnchorStyles.Left), System.Windows.Forms.AnchorStyles)
Me.G.FlatStyle = System.Windows.Forms.FlatStyle.Popup
Me.G.Font = New System.Drawing.Font("Verdana", 8.25!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
Me.G.Location = New System.Drawing.Point(200, 312)
Me.G.Name = "G"
Me.G.Size = New System.Drawing.Size(24, 23)
Me.G.TabIndex = 8
Me.G.TabStop = False
Me.G.Text = "G"
'
'H
'
Me.H.Anchor = CType((System.Windows.Forms.AnchorStyles.Bottom Or System.Windows.Forms.AnchorStyles.Left), System.Windows.Forms.AnchorStyles)
Me.H.FlatStyle = System.Windows.Forms.FlatStyle.Popup
Me.H.Font = New System.Drawing.Font("Verdana", 8.25!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
Me.H.Location = New System.Drawing.Point(232, 312)
Me.H.Name = "H"
Me.H.Size = New System.Drawing.Size(24, 23)
Me.H.TabIndex = 9
Me.H.TabStop = False
Me.H.Text = "H"
'
'I
'
Me.I.Anchor = CType((System.Windows.Forms.AnchorStyles.Bottom Or System.Windows.Forms.AnchorStyles.Left), System.Windows.Forms.AnchorStyles)
Me.I.FlatStyle = System.Windows.Forms.FlatStyle.Popup
Me.I.Font = New System.Drawing.Font("Verdana", 8.25!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
Me.I.Location = New System.Drawing.Point(264, 312)
Me.I.Name = "I"
Me.I.Size = New System.Drawing.Size(24, 23)
Me.I.TabIndex = 10
Me.I.TabStop = False
Me.I.Text = "I"
'
'J
'
Me.J.Anchor = CType((System.Windows.Forms.AnchorStyles.Bottom Or System.Windows.Forms.AnchorStyles.Left), System.Windows.Forms.AnchorStyles)
Me.J.FlatStyle = System.Windows.Forms.FlatStyle.Popup
Me.J.Font = New System.Drawing.Font("Verdana", 8.25!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
Me.J.Location = New System.Drawing.Point(296, 312)
Me.J.Name = "J"
Me.J.Size = New System.Drawing.Size(24, 23)
Me.J.TabIndex = 11
Me.J.TabStop = False
Me.J.Text = "J"
'
'K
'
Me.K.Anchor = CType((System.Windows.Forms.AnchorStyles.Bottom Or System.Windows.Forms.AnchorStyles.Left), System.Windows.Forms.AnchorStyles)
Me.K.FlatStyle = System.Windows.Forms.FlatStyle.Popup
Me.K.Font = New System.Drawing.Font("Verdana", 8.25!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
Me.K.Location = New System.Drawing.Point(328, 312)
Me.K.Name = "K"
Me.K.Size = New System.Drawing.Size(24, 23)
Me.K.TabIndex = 12
Me.K.TabStop = False
Me.K.Text = "K"
'
'L
'
Me.L.Anchor = CType((System.Windows.Forms.AnchorStyles.Bottom Or System.Windows.Forms.AnchorStyles.Left), System.Windows.Forms.AnchorStyles)
Me.L.FlatStyle = System.Windows.Forms.FlatStyle.Popup
Me.L.Font = New System.Drawing.Font("Verdana", 8.25!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
Me.L.Location = New System.Drawing.Point(360, 312)
Me.L.Name = "L"
Me.L.Size = New System.Drawing.Size(24, 23)
Me.L.TabIndex = 13
Me.L.TabStop = False
Me.L.Text = "L"
'
'M
'
Me.M.Anchor = CType((System.Windows.Forms.AnchorStyles.Bottom Or System.Windows.Forms.AnchorStyles.Left), System.Windows.Forms.AnchorStyles)
Me.M.FlatStyle = System.Windows.Forms.FlatStyle.Popup
Me.M.Font = New System.Drawing.Font("Verdana", 8.25!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
Me.M.Location = New System.Drawing.Point(392, 312)
Me.M.Name = "M"
Me.M.Size = New System.Drawing.Size(24, 23)
Me.M.TabIndex = 14
Me.M.TabStop = False
Me.M.Text = "M"
'
'N
'
Me.N.Anchor = CType((System.Windows.Forms.AnchorStyles.Bottom Or System.Windows.Forms.AnchorStyles.Left), System.Windows.Forms.AnchorStyles)
Me.N.FlatStyle = System.Windows.Forms.FlatStyle.Popup
Me.N.Font = New System.Drawing.Font("Verdana", 8.25!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
Me.N.Location = New System.Drawing.Point(424, 312)
Me.N.Name = "N"
Me.N.Size = New System.Drawing.Size(24, 23)
Me.N.TabIndex = 15
Me.N.TabStop = False
Me.N.Text = "N"
'
'O
'
Me.O.Anchor = CType((System.Windows.Forms.AnchorStyles.Bottom Or System.Windows.Forms.AnchorStyles.Left), System.Windows.Forms.AnchorStyles)
Me.O.FlatStyle = System.Windows.Forms.FlatStyle.Popup
Me.O.Font = New System.Drawing.Font("Verdana", 8.25!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
Me.O.Location = New System.Drawing.Point(456, 312)
Me.O.Name = "O"
Me.O.Size = New System.Drawing.Size(24, 23)
Me.O.TabIndex = 16
Me.O.TabStop = False
Me.O.Text = "O"
'
'P
'
Me.P.Anchor = CType((System.Windows.Forms.AnchorStyles.Bottom Or System.Windows.Forms.AnchorStyles.Left), System.Windows.Forms.AnchorStyles)
Me.P.FlatStyle = System.Windows.Forms.FlatStyle.Popup
Me.P.Font = New System.Drawing.Font("Verdana", 8.25!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
Me.P.Location = New System.Drawing.Point(488, 312)
Me.P.Name = "P"
Me.P.Size = New System.Drawing.Size(24, 23)
Me.P.TabIndex = 17
Me.P.TabStop = False
Me.P.Text = "P"
'
'Q
'
Me.Q.Anchor = CType((System.Windows.Forms.AnchorStyles.Bottom Or System.Windows.Forms.AnchorStyles.Left), System.Windows.Forms.AnchorStyles)
Me.Q.FlatStyle = System.Windows.Forms.FlatStyle.Popup
Me.Q.Font = New System.Drawing.Font("Verdana", 8.25!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
Me.Q.Location = New System.Drawing.Point(520, 312)
Me.Q.Name = "Q"
Me.Q.Size = New System.Drawing.Size(24, 23)
Me.Q.TabIndex = 18
Me.Q.TabStop = False
Me.Q.Text = "Q"
'
'R
'
Me.R.Anchor = CType((System.Windows.Forms.AnchorStyles.Bottom Or System.Windows.Forms.AnchorStyles.Left), System.Windows.Forms.AnchorStyles)
Me.R.FlatStyle = System.Windows.Forms.FlatStyle.Popup
Me.R.Font = New System.Drawing.Font("Verdana", 8.25!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
Me.R.Location = New System.Drawing.Point(552, 312)
Me.R.Name = "R"
Me.R.Size = New System.Drawing.Size(24, 23)
Me.R.TabIndex = 19
Me.R.TabStop = False
Me.R.Text = "R"
'
'S
'
Me.S.Anchor = CType((System.Windows.Forms.AnchorStyles.Bottom Or System.Windows.Forms.AnchorStyles.Left), System.Windows.Forms.AnchorStyles)
Me.S.FlatStyle = System.Windows.Forms.FlatStyle.Popup
Me.S.Font = New System.Drawing.Font("Verdana", 8.25!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
Me.S.Location = New System.Drawing.Point(376, 344)
Me.S.Name = "S"
Me.S.Size = New System.Drawing.Size(24, 23)
Me.S.TabIndex = 20
Me.S.TabStop = False
Me.S.Text = "S"
'
'T
'
Me.T.Anchor = CType((System.Windows.Forms.AnchorStyles.Bottom Or System.Windows.Forms.AnchorStyles.Left), System.Windows.Forms.AnchorStyles)
Me.T.FlatStyle = System.Windows.Forms.FlatStyle.Popup
Me.T.Font = New System.Drawing.Font("Verdana", 8.25!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
Me.T.Location = New System.Drawing.Point(408, 344)
Me.T.Name = "T"
Me.T.Size = New System.Drawing.Size(24, 23)
Me.T.TabIndex = 21
Me.T.TabStop = False
Me.T.Text = "T"
'
'U
'
Me.U.Anchor = CType((System.Windows.Forms.AnchorStyles.Bottom Or System.Windows.Forms.AnchorStyles.Left), System.Windows.Forms.AnchorStyles)
Me.U.FlatStyle = System.Windows.Forms.FlatStyle.Popup
Me.U.Font = New System.Drawing.Font("Verdana", 8.25!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
Me.U.Location = New System.Drawing.Point(440, 344)
Me.U.Name = "U"
Me.U.Size = New System.Drawing.Size(24, 23)
Me.U.TabIndex = 22
Me.U.TabStop = False
Me.U.Text = "U"
'
'V
'
Me.V.Anchor = CType((System.Windows.Forms.AnchorStyles.Bottom Or System.Windows.Forms.AnchorStyles.Left), System.Windows.Forms.AnchorStyles)
Me.V.FlatStyle = System.Windows.Forms.FlatStyle.Popup
Me.V.Font = New System.Drawing.Font("Verdana", 8.25!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
Me.V.Location = New System.Drawing.Point(472, 344)
Me.V.Name = "V"
Me.V.Size = New System.Drawing.Size(24, 23)
Me.V.TabIndex = 23
Me.V.TabStop = False
Me.V.Text = "V"
'
'Y
'
Me.Y.Anchor = CType((System.Windows.Forms.AnchorStyles.Bottom Or System.Windows.Forms.AnchorStyles.Left), System.Windows.Forms.AnchorStyles)
Me.Y.FlatStyle = System.Windows.Forms.FlatStyle.Popup
Me.Y.Font = New System.Drawing.Font("Verdana", 8.25!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
Me.Y.Location = New System.Drawing.Point(504, 344)
Me.Y.Name = "Y"
Me.Y.Size = New System.Drawing.Size(24, 23)
Me.Y.TabIndex = 24
Me.Y.TabStop = False
Me.Y.Text = "Y"
'
'Z
'
Me.Z.Anchor = CType((System.Windows.Forms.AnchorStyles.Bottom Or System.Windows.Forms.AnchorStyles.Left), System.Windows.Forms.AnchorStyles)
Me.Z.FlatStyle = System.Windows.Forms.FlatStyle.Popup
Me.Z.Font = New System.Drawing.Font("Verdana", 8.25!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
Me.Z.Location = New System.Drawing.Point(536, 344)
Me.Z.Name = "Z"
Me.Z.Size = New System.Drawing.Size(24, 23)
Me.Z.TabIndex = 25
Me.Z.TabStop = False
Me.Z.Text = "Z"
'
'GroupBox5
'
Me.GroupBox5.Anchor = CType((System.Windows.Forms.AnchorStyles.Bottom Or System.Windows.Forms.AnchorStyles.Left), System.Windows.Forms.AnchorStyles)
Me.GroupBox5.Location = New System.Drawing.Point(376, 376)
Me.GroupBox5.Name = "GroupBox5"
Me.GroupBox5.Size = New System.Drawing.Size(200, 16)
Me.GroupBox5.TabIndex = 31
Me.GroupBox5.TabStop = False
'
'GroupBox4
'
Me.GroupBox4.Anchor = CType(((System.Windows.Forms.AnchorStyles.Bottom Or System.Windows.Forms.AnchorStyles.Left) _
Or System.Windows.Forms.AnchorStyles.Right), System.Windows.Forms.AnchorStyles)
Me.GroupBox4.Location = New System.Drawing.Point(584, 312)
Me.GroupBox4.Name = "GroupBox4"
Me.GroupBox4.Size = New System.Drawing.Size(24, 192)
Me.GroupBox4.TabIndex = 32
Me.GroupBox4.TabStop = False
'
'Datagrid
'
Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
Me.ClientSize = New System.Drawing.Size(616, 514)
Me.Controls.Add(Me.GroupBox5)
Me.Controls.Add(Me.Z)
Me.Controls.Add(Me.Y)
Me.Controls.Add(Me.V)
Me.Controls.Add(Me.U)
Me.Controls.Add(Me.T)
Me.Controls.Add(Me.S)
Me.Controls.Add(Me.R)
Me.Controls.Add(Me.Q)
Me.Controls.Add(Me.P)
Me.Controls.Add(Me.O)
Me.Controls.Add(Me.N)
Me.Controls.Add(Me.M)
Me.Controls.Add(Me.L)
Me.Controls.Add(Me.K)
Me.Controls.Add(Me.J)
Me.Controls.Add(Me.I)
Me.Controls.Add(Me.H)
Me.Controls.Add(Me.G)
Me.Controls.Add(Me.F)
Me.Controls.Add(Me.E)
Me.Controls.Add(Me.D)
Me.Controls.Add(Me.C)
Me.Controls.Add(Me.B)
Me.Controls.Add(Me.A)
Me.Controls.Add(Me.Grid)
Me.Controls.Add(Me.btCargar)
Me.Controls.Add(Me.GroupBox1)
Me.Controls.Add(Me.GroupBox2)
Me.Controls.Add(Me.GroupBox3)
Me.Controls.Add(Me.PictureBox1)
Me.Controls.Add(Me.GroupBox4)
Me.Icon = CType(resources.GetObject("$this.Icon"), System.Drawing.Icon)
Me.MinimizeBox = False
Me.Name = "Datagrid"
Me.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen
Me.Text = "Agenda telefónica - Archivo XML"
CType(Me.Grid, System.ComponentModel.ISupportInitialize).EndInit()
Me.GroupBox1.ResumeLayout(False)
Me.GroupBox2.ResumeLayout(False)
Me.GroupBox3.ResumeLayout(False)
Me.ResumeLayout(False)
End Sub
#End Region
'Al cargar el formulario
Private Sub Datagrid_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Me.ToolTip1.SetToolTip(Me.btCargar, "Leer el archivo XML y cargar sus datos en el DataSet")
End Sub
'al maximizar el datagrid, mostrar el control PictureBox
'con la imagen de miliuco
Private Sub Datagrid_SizeChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.SizeChanged
If Me.WindowState = FormWindowState.Maximized Then
Me.PictureBox1.Visible = True
Else
Me.PictureBox1.Visible = False
End If
End Sub
Private Sub btCargar_XLM(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btCargar.Click
'Si el archivo XML SÍ está abierto, simplemente informar
If abierto = True Then
Dim aviso As String = "El archivo XML ya está cargado en el DataSet"
MessageBox.Show(aviso.ToUpper, "Aviso al usuario", MessageBoxButtons.OK)
End If
'Si el archivo XML NO está abierto
If abierto = False Then
Try
'Cuadro de diálogo para elegir el archivo XML
dlgFile = New OpenFileDialog
dlgFile.Filter = "Archivo de datos XML(*.xml)|*.xml"
dlgFile.Title = "Selecciona el origen XML"
'Si el diálogo devuelve OK
If dlgFile.ShowDialog() = DialogResult.OK Then
'Nombre del archivo elegido, con su ruta completa,
'equivale al archivo XML
ruta = dlgFile.FileName
'DataSet: contiene una copia de los datos, en esquema XML,
'independiente del proveedor, con sus elementos tablas y relaciones.
'Es el verdadero almacén de datos desconectados
datos = New DataSet
'Rellenar el DataSet desde el archivo XML
datos.ReadXml(ruta)
'valores por defecto de los campos de la fila de nueva inserción
'para que no aparezca el texto "(null)" al pasar el cursor a esa fila,
'también se puede configurar con la propiedada NullText de las
'DataGridTextBoxColumn que se crean para cada columna del DataGrid
'Dim i As Integer
'For i = 0 To (Me.datos.Tables("Agendatb").Columns.Count - 1)
' Me.datos.Tables("Agendatb").Columns(i).DefaultValue = ""
'Next
'configurar varias opciones del Datagrid por código
Me.Grid.CaptionText = "Listado de teléfonos"
Me.Grid.CaptionBackColor = Color.Black
Me.Grid.CaptionForeColor = Color.Yellow
Me.Grid.GridLineColor = Color.Navy
Me.Grid.GridLineStyle = DataGridLineStyle.Solid
'Me.Grid.CaptionFont = New Font("Verdana", 10, FontStyle.Bold)
'Me.Grid.Font = New Font("Courier", 10, FontStyle.Regular)
'crear un objeto para estilos en el Datagrid
Dim estilo As New DataGridTableStyle
estilo.MappingName = "Agendatb"
estilo.BackColor = Color.White
estilo.AlternatingBackColor = Color.LightGray
'Crear objetos del tipo DataGridTextBoxColumn
'para cada columna de la tabla del Datagrid
Dim columna As New DataGridTextBoxColumn
'Configurar cada columna
'Esta es la primera columna
columna = New DataGridTextBoxColumn
columna.TextBox.MaxLength = 50
columna.Alignment = HorizontalAlignment.Left
columna.HeaderText = "Nombre del contacto"
'columna del Dataset enlazada con esta columna del Datagrid
columna.MappingName = "Nombre"
columna.Width = 330
'texto que se muestra cuando la columna tiene valor null
columna.NullText = ""
'añadir la columna a los estilos del Datagrid
estilo.GridColumnStyles.Add(columna)
'CREACION DEL ESTILO PARA LAS COLUMNAS ESPECIALES
'Esta es la segunda columna (que acepta sólo números)
'repetimos el proceso de la primera columna pero en vez de ser
'DataGridTextBoxColumn será DataGridDigitsTextBoxColumn, que hemos definido
'en la clase DataGridDigitsTextBoxColumn del archivo DataGridDigitsTextBoxColumn.vb
columna = New DataGridTextBoxColumnNumbers
columna.TextBox.MaxLength = 9
columna.Alignment = HorizontalAlignment.Left
columna.HeaderText = "Teléfono 1"
'columna del Dataset enlazada con esta columna del Datagrid
columna.MappingName = "Teléfono1"
columna.Width = 100
'texto que se muestra cuando la columna tiene valor null
columna.NullText = ""
'añadir la columna a los estilos del Datagrid
estilo.GridColumnStyles.Add(columna)
'Esta es la tercera columna (que acepta sólo números)
'se crea igual que la segunda columna
columna = New DataGridTextBoxColumnNumbers
columna.TextBox.MaxLength = 9
columna.Alignment = HorizontalAlignment.Left
columna.HeaderText = "Teléfono 2"
'columna del Dataset enlazada con esta columna del Datagrid
columna.MappingName = "Teléfono2"
columna.Width = 100
'texto que se muestra cuando la columna tiene valor null
columna.NullText = ""
'añadir la columna a los estilos del Datagrid
estilo.GridColumnStyles.Add(columna)
'Añadir el estilo personalizado a la colección de estilos de tablas del Datagrid
Me.Grid.TableStyles.Add(estilo)
'asignar Dataset al Datagrid
Me.Grid.DataSource = Me.datos.Tables("AgendaTb")
'abrir la agenda por la letra A (registros ordenados)
Me.txFiltro.Text = "a".ToUpper
Dim vista As New DataView
vista.Table = datos.Tables("Agendatb")
'filtro SQL: registros que empiecen por el texto escrito en el TextBox
vista.RowFilter = "Nombre LIKE '" & Me.txFiltro.Text & "%'"
vista.Sort = "Nombre"
'nuevo origen del DataDrid: la vista personalizada
Me.Grid.DataSource = vista
'contar el número de registros que presenta el DataGrid
Dim n As Integer
n = vista.Count
Label2.Text = "Número de registros: " & n
'recargar el DataGrid
Me.Grid.Update()
'Habilitar los botones Actualizar y Quitar filtro
'crear los Tooltips para esos controles
Me.btActualizar.Enabled = True
Me.ToolTip1.SetToolTip(Me.btActualizar, "Modificar la base de datos con los cambios realizados en el DataSet")
Me.btQuitar.Enabled = True
Me.ToolTip1.SetToolTip(Me.btQuitar, "Mostrar de nuevo todos los registros")
'Habilitar la escritura en el Texbox
Me.txFiltro.ReadOnly = False
'Para saber que el archivo XML SÍ está abierto
abierto = True
End If
Catch pollo As Exception
MessageBox.Show(pollo.Message.ToUpper, "Aviso al usuario", MessageBoxButtons.OK)
End Try
End If
End Sub
Private Sub btFiltrar_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btFiltrar.Click
'aplicar un filtro a la tabla AgendaTb del DataSet mediante un DataView
'DataView permite personalizar las vistas de las tablas
'Si el archivo XML SÍ está abierto
If abierto = True Then
Try
If Me.txFiltro.Text.Length > 0 Then
Dim vista As New DataView
vista.Table = datos.Tables("Agendatb")
'filtro SQL: registros que empiecen por el texto escrito en el TextBox
vista.RowFilter = "Nombre LIKE '" & Me.txFiltro.Text & "%'"
vista.Sort = "Nombre"
'nuevo origen del DataDrid: la vista personalizada
Me.Grid.DataSource = vista
'recargar el DataGrid
Me.Grid.Update()
Dim n As Integer
n = vista.Count
'Dim aviso4 As String = a & " Registros recuperados "
'MessageBox.Show(aviso4, "Filtrado", MessageBoxButtons.OK)
Me.Label2.Text = "Número de registros: " & n
End If
Catch pollo As Exception
MessageBox.Show(pollo.Message.ToUpper, "Aviso al usuario", MessageBoxButtons.OK)
End Try
'Si el archivo XML NO está abierto
'Else
' Dim aviso4 As String = "Primero has de cargar el archivo XML"
' MessageBox.Show(aviso4.ToUpper, "Aviso al usuario")
End If
End Sub
'Quitar el filtro a la tabla Agenda del DataSet
Private Sub quitar_filtro(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btQuitar.Click
'Si el archivo XML SÍ está abierto
If abierto = True Then
Try
Dim vista As New DataView
vista.Table = datos.Tables("Agendatb")
vista.Sort = "Nombre"
'recuperar de nuevo todos los registros
Me.Grid.DataSource = vista
'recargar el DataGrid
Me.Grid.Update()
Dim n As Integer
n = vista.Count
'Dim aviso4 As String = a & " Registros recuperados "
'MessageBox.Show(aviso4, "Filtrado", MessageBoxButtons.OK)
Me.Label2.Text = "Número de registros: " & n
Me.txFiltro.Text = ""
Catch pollo As Exception
MessageBox.Show(pollo.Message.ToUpper, "Aviso al usuario", MessageBoxButtons.OK)
End Try
' 'Si el archivo XML NO está abierto
'Else
' Dim aviso4 As String = "Primero has de cargar el archivo XML"
' MessageBox.Show(aviso4.ToUpper, "Aviso al usuario")
End If
End Sub
'actualizar los cambios realizados en el DataGrid ( DataSet -> DataAdapter -> base de datos)
Private Sub btActualizar_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btActualizar.Click
'Si el archivo XML SÍ está abierto
If abierto = True Then
Try
'escribir el DataSet al archivo XML
datos.WriteXml(ruta)
datos.Clear()
datos.ReadXml(ruta)
Dim aviso5 As String = "Archivo XML modificado con éxito"
MessageBox.Show(aviso5.ToUpper, "Aviso al usuario", MessageBoxButtons.OK)
'contar el número de registros que presenta el DataGrid
Dim n As Integer
n = Me.datos.Tables("Agendatb").Rows.Count
Label2.Text = "Número de registros: " & n
Me.txFiltro.Text = ""
Catch pollo As Exception
MessageBox.Show(pollo.Message.ToUpper, "Aviso al usuario", MessageBoxButtons.OK)
End Try
' 'Si el archivo XML NO está abierto
'Else
' Dim aviso3 As String = "Primero has de cargar el archivo XML"
' MessageBox.Show(aviso3.ToUpper, "Aviso al usuario")
End If
End Sub
'Filtrar registros por la letra inicial
Private Sub A_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles A.Click, _
B.Click, C.Click, D.Click, E.Click, F.Click, G.Click, H.Click, I.Click, J.Click, K.Click, L.Click, M.Click, _
N.Click, O.Click, P.Click, Q.Click, R.Click, S.Click, T.Click, U.Click, V.Click, Y.Click, Z.Click
'aplicar un filtro a la tabla Agenda del DataSet mediante un DataView
'DataView permite personalizar las vistas de las tablas
'Si el archivo XML SÍ está abierto
If abierto = True Then
Try
Dim vista As New DataView
vista.Table = datos.Tables("Agendatb")
'filtro SQL: registros que empiecen por el texto escrito en el TextBox
vista.RowFilter = "Nombre LIKE '" & sender.Text & "%'"
vista.Sort = "Nombre"
'nuevo origen del DataDrid: la vista personalizada
Me.Grid.DataSource = vista
'recargar el DataGrid
Me.Grid.Update()
Dim n As Integer
n = vista.Count
'Dim aviso4 As String = a & " Registros recuperados "
'MessageBox.Show(aviso4, "Filtrado", MessageBoxButtons.OK)
Me.Label2.Text = "Número de registros: " & n
Me.txFiltro.Text = sender.Text.ToUpper
Catch pollo As Exception
MessageBox.Show(pollo.Message.ToUpper, "Aviso al usuario", MessageBoxButtons.OK)
End Try
' 'Si el archivo XML NO está abierto
'Else
' Dim aviso4 As String = "Primero has de cargar el archivo XML"
' MessageBox.Show(aviso4.ToUpper, "Aviso al usuario")
End If
End Sub
'Activar el botón filtrar sólo si hay algo en la caja de texto txFiltro
Private Sub txFiltro_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txFiltro.TextChanged
'si hay algo escrito en txFiltro
If Me.txFiltro.Text.Length > 0 Then
Me.btFiltrar.Enabled = True
Me.ToolTip1.SetToolTip(Me.btFiltrar, "Filtrar por texto coincidente")
End If
'si no hay nada escrito en txFiltro
If Me.txFiltro.Text.Length = 0 Then
Me.btFiltrar.Enabled = False
End If
End Sub
'Salir del programa
Private Sub btSalir_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btSalir.Click
Application.Exit()
End Sub
End Class
End Namespace
' LEER UN ARCHIVO DE DATOS EN FORMATO XML
' MOSTRARLO EN UN DATAGRID PERSONALIZADO
' LAS CAJAS DE TEXTO CON LOS TELÉFONOS SÓLO ACEPTAN NÚMEROS
'
' FORMULARIO SECUNDARIO: DataGridTextBoxColumnNumbers.vb
' --------------------------------------
Option Strict Off
Option Explicit On
'Espacios de nombres necesarios
Imports Microsoft.VisualBasic
Imports System
Imports System.ComponentModel
Imports System.Windows.Forms
'Espacio de nombre propio de la aplicación, al pertenecer a este espacio
'de nombres las 2 clases del ejercicio (Datagrid y DataGridDigitsTextBoxColumn)
'hay herencia entre ellas y podemos usar esta clase DataGridDigitsTextBoxColumn
'dentro de la otra clase DataGrid
Namespace DataGridNumbersOnly
'Clase DataGridTextBoxColumnNumbers que definiremos en este archivo,
'hereda de DataGridTextBoxColumn
Public Class DataGridTextBoxColumnNumbers
Inherits DataGridTextBoxColumn
'Método constructor de la clase
Public Sub New()
'MyBase se refiere a la clase madre DataGridTextBoxColumn, de la que hereda
MyBase.New()
'la instrucción AddHandler asocia un evento a un manipulador de eventos
'aquí asocia la pulsación de una tecla en el TextBox con el manipulador
'de su evento KeyPress y refiere al procedimiento HandleKeyPress
AddHandler Me.TextBox.KeyPress, New System.Windows.Forms.KeyPressEventHandler(AddressOf HandleKeyPress)
End Sub
'PROCEDIMIENTO CON SENTENCIA IF
'Pocedimiento específico de configuración del cuadro de texto en cuanto a teclas pulsadas
'Private Sub HandleKeyPress(ByVal sender As Object, ByVal e As KeyPressEventArgs)
'- ignorar si no es un número
'- ignorar si hay más de 9 caracteres
'If (Not (System.Char.IsDigit(e.KeyChar))) Then
'poner e.Handled a False equivale a decir que la tecla no ha sido manejada por el evento
'y, por tanto, la pulsación se envía, pero si e.Handled es True, equivale a decir que la tecla
'ya ha sido manejada por el evento (como si la tecla no hubiese sido pulsada, por tanto,
'ya no se envía esa pulsación).
'e.Handled = True
'End If
'If (Me.TextBox.Text.Length >= 10) AndAlso (Me.TextBox.SelectionLength = 0) Then
'e.Handled = True
'End If
'End Sub
'PROCEDIMIENTO CON SENTENCIA CASE... ELSE
'Pocedimiento específico de configuración del cuadro de texto en cuanto a teclas pulsadas
Private Sub HandleKeyPress(ByVal sender As Object, ByVal e As KeyPressEventArgs)
Select Case e.KeyChar ' según el valor de la tecla pulsada
' pasan valores si la tecla pulsada es un número de 0 a 9
Case "1"c, "2"c, "3"c, "4"c, "5"c, "6"c, "7"c, "8"c, "9"c, "0"c
e.Handled = False
' si la propiedad Handled del objeto e se pone a True indico
' que la tecla ha sido "manejada" por el evento, equivale a
' indicar que la tecla no ha sido pulsada, pero si la propiedad
' Handled del objeto e se pone a False indico que la tecla
' todavía no ha sido "manejada" por el evento y se envía.
Case Else ' en los demás casos, no se pasa la pulsación
e.Handled = True
End Select
End Sub
End Class
End Namespace