dataset

02/08/2004 - 19:05 por Plata | Informe spam
Tengo un dataset asi

Cliente1 2000 35
CLiente1 2001 30
Cliente2 2001 20
cliente2 2003 35
cliente3 2002 20

alguna manera de usar el rowfilter para mostrar solo las
filas del datagrid donde no se repita el cliente?? es
decir que despliegue esto:

cliente1 2001 30
cliente2 2001 20
cliente3 2002 20
 

Leer las respuestas

#1 Tristan
02/08/2004 - 21:39 | Informe spam
Pues no lo creo. ¿Con que fila se debería quedar?. ¿Con la primera, con la
segunda?. En tu ejemplo has seleccionado la segunda en unos casos, la
primera en otros...

Yo creo que más bien lo que necesitas es crear por ti mismo el DataTable con
las filas convenientes. Prueba algo así:

'Cargando la tabla (tu lo harías con tu dataadapter.Fill)
Dim tabla As New DataTable
tabla.Columns.Add("cliente", GetType(String))
tabla.Columns.Add("año", GetType(Integer))
tabla.Columns.Add("otro", GetType(Integer))
tabla.Rows.Add(New Object() {"Cliente1", 2000, 35})
tabla.Rows.Add(New Object() {"Cliente1", 2001, 30})
tabla.Rows.Add(New Object() {"Cliente2", 2001, 20})
tabla.Rows.Add(New Object() {"Cliente2", 2003, 35})
tabla.Rows.Add(New Object() {"Cliente3", 2002, 20})

'Seleccionando filas únicas
Dim tabla2 As DataTable = tabla.Clone()
tabla2.PrimaryKey = New DataColumn() {tabla2.Columns("cliente")}
For Each fila As DataRow In tabla.Rows
If Not tabla2.Rows.Contains(fila("cliente")) Then
tabla2.ImportRow(fila)
End If
Next

Juan Carlos Badiola
MVP - C#

Preguntas similares