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
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


0