radeon_snorky
06-09-2010, 19:06
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:
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
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
come lo vedete? brutto forte? come lo miglioro? o cambio approccio?
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:
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
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
come lo vedete? brutto forte? come lo miglioro? o cambio approccio?