Ver Mensaje Individual
  #6 (permalink)  
Antiguo 10/04/2008, 10:19
nenure
 
Fecha de Ingreso: marzo-2008
Mensajes: 65
Antigüedad: 16 años, 1 mes
Puntos: 0
Re: AYUDAAAA gridviewrow

Hola! He conseguido quitar esos fallos, pero tengo otros y ya no se que hacer!

Os mando el codigo completo para que lo veais. MUCHAS GRACIAS.

EL FALLO QUE ME DA:

Error 1 'ClearSelection' no es un miembro de 'System.Web.UI.WebControls.DataGrid'.

Error 2 El tipo 'DataGridViewRow' no está definido.

Error 3 'Rows' no es un miembro de 'System.Web.UI.WebControls.DataGrid'.


EL CODIGO DEL CODEBEHIND:

Imports System
Imports System.Data
Imports System.Data.OleDb
Imports Microsoft.VisualBasic

Partial Class Inmobiliarias_mientrasescribe
Inherits System.Web.UI.Page
Private da As OleDbDataAdapter
Private dt As DataTable
Private filas As DataGrid

Private iniciando As Boolean = True
Private conexion As String ="Provider=MSDAORA;Data Source=nombre;Password=pass;User ID=usu"
Private seleccion As String = _
"SELECT inmobiliaria, zona FROM nerea2_inmobiliarias"
Private Sub Form1_Load( _
ByVal sender As Object, _
ByVal e As EventArgs) _
Handles MyBase.Load

Me.txtApellidos.Text = ""

da = New OleDbDataAdapter(seleccion, conexion)
dt = New DataTable
da.Fill(dt)

Me.datosClientes.DataSource = dt

iniciando = False
End Sub
Private Sub txtApellidos_TextChanged( _
ByVal sender As Object, _
ByVal e As EventArgs) _
Handles txtApellidos.TextChanged

If iniciando Then Exit Sub

' Buscar en el DataTable usando el método Select
' que es como un filtro WHERE en una cadena de selección.

' El resultado se devuelve como un array de tipo DataRow
Dim filas() As DataRow

' Si solo quieres mostrar los que empiecen por lo escrito.
' Al escribir "s" se buscarán los que empiecen por esa letra.
filas = dt.Select("inmobiliaria LIKE '" & txtApellidos.Text & "%'")

' Borrar los elementos anteriores
Me.listaApellidos.Items.Clear()

' Si hay datos, mostrar los apellidos
If filas.Length > 0 Then

' Recorrer cada fila y mostrar los apellidos
For Each dr As DataRow In filas

Me.listaApellidos.Items.Add( _
dr("inmobiliaria").ToString & ", " & _
dr("zona").ToString)

Next
End If
End Sub

Private Sub listaApellidos_SelectedIndexChanged( _
ByVal sender As Object, _
ByVal e As EventArgs) _
Handles listaApellidos.SelectedIndexChanged

If iniciando Then Exit Sub

' Al hacer clic, mostrar el dato
Me.txtApellidos.Text = Me.listaApellidos.SelectedItem.ToString

' Buscarlo en el DataGridView (de forma manual, no conozco otra forma...)

' Eliminar las selecciones anteriores
Me.datosClientes.ClearSelection()

For Each fila As DataGridViewRow In Me.datosClientes.Rows
' Si es el mismo apellido del textBox

' Curiosamente si no son los mismos datos
' se produce un error de que d.Cells(...) es Nothing
' En realidad de "curioso" no tiene nada,
' es que es la última fila, que está vacía...
If fila.Cells("inmobiliaria").Value Is Nothing _
OrElse fila.Cells Is Nothing Then
Continue For
End If

' Si se quiere tener en cuenta el nombre y los apellidos
Dim i As Integer = Me.txtApellidos.Text.IndexOf(",")

If i > -1 Then
' En este ejemplo, el formato es Apellidos, Nombre
Dim nombre, apellidos As String
apellidos = Me.txtApellidos.Text.Substring(0, i).TrimEnd()
nombre = Me.txtApellidos.Text.Substring(i + 1).TrimStart()

If nombre = fila.Cells("zona").Value.ToString _
AndAlso apellidos = fila.Cells("inmobiliaria").Value.ToString Then
' Seleccionamos la fila
Me.datosClientes.Rows(fila.Index).Selected = True
' nos aseguramos de que sea visible
Me.datosClientes.FirstDisplayedScrollingRowIndex = fila.Index
Exit For
End If
Else
If Me.txtApellidos.Text = fila.Cells("inmobiliaria").Value.ToString Then
' Seleccionamos la fila
Me.datosClientes.Rows(fila.Index).Selected = True
' nos aseguramos de que sea visible
Me.datosClientes.FirstDisplayedScrollingRowIndex = fila.Index
Exit For
End If
End If
Next
End Sub

End Class