Visual Basic.NET - Llenar ListView

 
Vista:
sin imagen de perfil
Val: 28
Ha disminuido su posición en 3 puestos en Visual Basic.NET (en relación al último mes)
Gráfica de Visual Basic.NET

Llenar ListView

Publicado por Adolfo (55 intervenciones) el 09/04/2011 21:42:19
Tengo el siguiente codigo fuente para llenar un 2nd ListView (LVSubCategorias), esto de acuerdo al valor seleccionado en el primer ListView (LVCategorias)

Si corro el programa con este SELECT:
Dim strSQL2 As String = "SELECT * FROM TBSubCategorias"

El listView (LVSubCategorias) si se llena, pero si lo corro con este otro SELECT:
Dim strSQL2 As String = "SELECT * FROM TBSubCategorias WHERE CodigoCategoria = '" & VarCodigoCat & "'"

No se llena. ademas si trato de limpiar el LVSubCategorias antes de llenarlo, este no lo hace, solo se limpia el ListView pero no se llena.

LVSubCategorias.Clear()

Agradeceria cualquier sugerencia, pues he tratodo de todo y no se porque no funciona.


Private Sub LVCategorias_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles LVCategorias.SelectedIndexChanged

Dim VarCodigoCat As String
VarCodigoCat = LVCategorias.SelectedItems(0).Text

'LVSubCategorias.Clear()

'Dim strSQL2 As String = "SELECT * FROM TBSubCategorias WHERE CodigoCategoria = '" & VarCodigoCat & "'"
Dim strSQL2 As String = "SELECT * FROM TBSubCategorias"

Dim da2 As New OleDbDataAdapter(strSQL2, m_cn)
da2.Fill(m_DataTable)

For Each Dt_Row As DataRow In m_DataTable.Rows
Dim LI2 As New ListViewItem
LI2.Text = Dt_Row.Item("CodigoSubCategoria").ToString
LI2.SubItems.Add(Dt_Row.Item("SubCategoria").ToString)
LVSubCategorias.Items.Add(LI2)
Next

End Sub
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
sin imagen de perfil

Llenar ListView

Publicado por Joan B Fabregas (129 intervenciones) el 10/04/2011 21:04:41
Hola,

Has comprobado que la sentencia select devuelva registros?

Podrias hacer para verificar:

Private Sub LVCategorias_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles LVCategorias.SelectedIndexChanged

Dim VarCodigoCat As String
VarCodigoCat = LVCategorias.SelectedItems(0).Text

'LVSubCategorias.Clear()

'Dim strSQL2 As String = "SELECT * FROM TBSubCategorias WHERE CodigoCategoria = '" & VarCodigoCat & "'"
Dim strSQL2 As String = "SELECT * FROM TBSubCategorias"

Dim da2 As New OleDbDataAdapter(strSQL2, m_cn)
da2.Fill(m_DataTable)

If m_DataTable.Rows.Count > 0 Then

For Each Dt_Row As DataRow In m_DataTable.Rows
Dim LI2 As New ListViewItem
LI2.Text = Dt_Row.Item("CodigoSubCategoria").ToString
LI2.SubItems.Add(Dt_Row.Item("SubCategoria").ToString)
LVSubCategorias.Items.Add(LI2)
Next

Else
MsgBox("No hay datos")
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