|
|||||||
|
|
|
![]() |
|
|
Strumenti |
|
|
#1 |
|
Senior Member
Iscritto dal: Mar 2003
Messaggi: 2184
|
[VBNET] Checkedlistbox da db e ritorno...
ho una checkedlistbox con alcune voci... queste sono memorizzate in una tabella di un db (che contiene.... conterrà, meglio! anche mille altre cose...)
sto cercando il modo più veloce per fare le operazioni di inserimento/recupero delle informazioni, piuttosto che salvarmi un boolean per ogni voce (selezionata si/no) ho pensato di "tradurre" l'intera checkedlistbox in una stringa di 0 e 1 per ogni voce... ho realizzato una piccola applicazione per testare il codice, ho inserito due checkedlistbox, due pulsanti e una textbox (che simula il db) il codice: Codice:
Private Sub recupera_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles recupera.Click
Dim str As String
Dim strA As String
Dim count As Integer
str = TextBox1.Text
For count = 0 To str.Length - 1
strA = TextBox1.Text.Substring(count, 1)
If strA = "0" Then
CheckedListBox2.SetItemChecked(count, False)
End If
If strA = "1" Then
CheckedListBox2.SetItemChecked(count, True)
End If
Next
End Sub
Codice:
Private Sub salva_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles salva.Click
Dim stringa As String = ""
Dim i As Integer
Dim voce As String
For i = 0 To CheckedListBox1.Items.Count - 1
voce = CheckedListBox1.GetItemChecked(i)
If voce = "True" Then
voce = 1
End If
If voce = "False" Then
voce = 0
End If
stringa = stringa + voce
Next
TextBox1.Text = stringa
End Sub
|
|
|
|
|
| Strumenti | |
|
|
Tutti gli orari sono GMT +1. Ora sono le: 14:32.



















