Visualizzazione dei risultati da 1 a 3 su 3
  1. #1
    Utente di HTML.it
    Registrato dal
    Jan 2003
    Messaggi
    35

    [VB.Net] Aggiungere tag a elementi listbox

    Ciao a tutti,E' una cosa banale (Penso) ,ma non riesco a farla...
    Come faccio ad aggiungere un tag ad ogni elemento che aggiungo in una listbox???

    Da una query ad un database tiro fuori alcuni dati e li aggiungo ad una listbox,vorrei aggiungere anche un tag per ogni elemento aggiunto.
    Questo è il codice.

    Grazie

    codice:
    Dim RicercaAll As New System.Data.SqlServerCe.SqlCeCommand("SELECT * FROM Articoli WHERE ARCODART = ('" & txtcerca.Text & "') ORDER BY ARCODART ASC", ConnSqlCe)
    
                ConnSqlCe.Open()
    
                Dim rs2 As Data.SqlServerCe.SqlCeResultSet = RicercaAll.ExecuteResultSet(Data.SqlServerCe.ResultSetOptions.Scrollable)
    
                RicercaAll.ExecuteReader()
    
                If rs2.HasRows = False Then
                    MsgBox("Articolo Non Presente")
                Else
    
                    Do While rs2.Read
                        If rs2.IsDBNull(0) = False Then
                            ARCODART = CStr(rs2.GetValue(0))
                            If InStr(ARCODART, "'", CompareMethod.Text) Then
                                ARCODART = ARCODART.Replace("'", "''")
                            End If
                        Else
                            ARCODART = "   "
                        End If
    
                        If rs2.IsDBNull(1) = False Then
                            ARDESART = CStr(rs2.GetValue(1))
                            If InStr(ARDESART, "'", CompareMethod.Text) Then
                                ARDESART = ARDESART.Replace("'", "''")
                            End If
                        Else
                            ARDESART = "   "
                        End If
    
                        If rs2.IsDBNull(2) = False Then
                            ARDESSUP = CStr(rs2.GetValue(2))
                            If InStr(ARDESSUP, "'", CompareMethod.Text) Then
                                ARDESSUP = ARDESSUP.Replace("'", "''")
                            End If
                        Else
                            ARDESSUP = "   "
                        End If
    
                        If rs2.IsDBNull(3) = False Then
                            ARUM = CStr(rs2.GetValue(3))
                            If InStr(ARUM, "'", CompareMethod.Text) Then
                                ARUM = ARUM.Replace("'", "''")
                            End If
                        Else
                            ARUM = "   "
                        End If
    
                        If rs2.IsDBNull(4) = False Then
                            ARLIS = CStr(rs2.GetValue(4))
                            If InStr(ARLIS, "'", CompareMethod.Text) Then
                                ARLIS = ARLIS.Replace("'", "''")
                            End If
                        Else
                            ARLIS = "   "
                        End If
    
                        If rs2.IsDBNull(5) = False Then
                            ARCODIVA = CStr(rs2.GetValue(5))
                            If InStr(ARCODIVA, "'", CompareMethod.Text) Then
                                ARCODIVA = ARCODIVA.Replace("'", "''")
                            End If
                        Else
                            ARCODIVA = "   "
                        End If
    
                        If rs2.IsDBNull(6) = False Then
                            ARGRUMER = CStr(rs2.GetValue(6))
                            If InStr(ARGRUMER, "'", CompareMethod.Text) Then
                                ARGRUMER = ARGRUMER.Replace("'", "''")
                            End If
                        Else
                            ARGRUMER = "   "
                        End If
    
                        If rs2.IsDBNull(7) = False Then
                            ARCAT = CStr(rs2.GetValue(7))
                            If InStr(ARCAT, "'", CompareMethod.Text) Then
                                ARCAT = ARCAT.Replace("'", "''")
                            End If
                        Else
                            ARCAT = "   "
                        End If
    
                        Listbox1.Items.Add(ARDESART)
    
                    Loop
    
                    ConnSqlCe.Close()

  2. #2
    Se ho capito bene... :master:
    codice:
    Listbox1.Items.Add("TuoTag_" + ARDESART)
    Amaro C++, il gusto pieno dell'undefined behavior.

  3. #3
    Moderatore di Programmazione L'avatar di alka
    Registrato dal
    Oct 2001
    residenza
    Reggio Emilia
    Messaggi
    24,466
    Se invece si intende un oggetto personalizzato che consenta di associare dati aggiuntivi all'elemento, credo che sia sufficiente aggiungere direttamente l'oggetto in questione alla lista, ridefinendo il metodo ToString affinchè restituisca il testo che si vuole vedere per l'elemento all'interno del controllo.

    Ciao!
    MARCO BREVEGLIERI
    Software and Web Developer, Teacher and Consultant

    Home | Blog | Delphi Podcast | Twitch | Altro...

Permessi di invio

  • Non puoi inserire discussioni
  • Non puoi inserire repliche
  • Non puoi inserire allegati
  • Non puoi modificare i tuoi messaggi
  •  
Powered by vBulletin® Version 4.2.1
Copyright © 2025 vBulletin Solutions, Inc. All rights reserved.